Skip to content

Conversation

@jack-chester
Copy link

require_relative 'model'

class Control
include GameView
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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

Copy link

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*"
Copy link
Member

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants