Created
February 16, 2012 21:22
-
-
Save joshmvandercom/1847955 to your computer and use it in GitHub Desktop.
ruby_example.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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