Skip to content

Instantly share code, notes, and snippets.

@joshmvandercom
Created February 16, 2012 21:22
Show Gist options
  • Save joshmvandercom/1847955 to your computer and use it in GitHub Desktop.
Save joshmvandercom/1847955 to your computer and use it in GitHub Desktop.
ruby_example.rb
class Person
def initialize(food = 0)
@next_feeding_time = Time.now
feed(food)
end
def hungry?
@next_feeding_time < Time.now
end
def feed(food)
if hungry?
feed!(food)
else
puts "Not hungry"
end
end
def feed!(food)
@next_feeding_time = Time.now + food
puts "I just ate, will be hungry again in #{food} seconds"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment