-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jack Chester Solutions #29
base: master
Are you sure you want to change the base?
Conversation
require_relative 'model' | ||
|
||
class Control | ||
include GameView |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 spaces.
include GameView | ||
|
||
def run! | ||
Print::title_screen |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 spaces :)
def converse(input) | ||
|
||
if input.upcase == input | ||
if @asleep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the reader method?
if @asleep | ||
@sleep_count += 1 | ||
if @sleep_count == 3 | ||
@asleep = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Do you know what's happening here? Check out the book Metaprogramming Ruby 2.
- Why might you use it?
@jaybobo @matt529