Conversation
| require_relative 'model' | ||
|
|
||
| class Control | ||
| include GameView |
| include GameView | ||
|
|
||
| def run! | ||
| Print::title_screen |
| def converse(input) | ||
|
|
||
| if input.upcase == input | ||
| if @asleep |
| if @asleep | ||
| @sleep_count += 1 | ||
| if @sleep_count == 3 | ||
| @asleep = false |
There was a problem hiding this comment.
Keep in mind that here you're calling the instance variable directly. If you use self.asleep then you send a message to the object instead which gives you more flexibility in the long run if the definition of asleep were to change.
def asleep
in_bed && tucked_in
endThere was a problem hiding this comment.
Would it be correct to say this is akin to solely using the accessors (getX/setX) of certain other languages?
Honestly, it is also a bit nice to not see @ all over the place (I realized this when I started my MVCgame implementation) though that's a stylistic thing. Reminds me of CoffeeScript syntax though the details are pretty different.
| end | ||
| else | ||
| if @asleep | ||
| puts "*Grandma " + @name + " snores loudly*" |
There was a problem hiding this comment.
You can also use interpolation over concatenation.
http://ruby-for-beginners.rubymonstas.org/bonus/string_interpolation.html
|
|
||
| module Print | ||
|
|
||
| class <<self |
There was a problem hiding this comment.
- Do you know what's happening here? Check out the book Metaprogramming Ruby 2.
- Why might you use it?
@jaybobo @matt529