Skip to content

Instantly share code, notes, and snippets.

@BrianJoyce
Created October 18, 2012 02:49
Show Gist options
  • Save BrianJoyce/3909601 to your computer and use it in GitHub Desktop.
Save BrianJoyce/3909601 to your computer and use it in GitHub Desktop.
classes fuck around
class Food
def edible?
true
end
end
class Human
attr_reader :hungry
def initialize(name = '')
@hungry = false
@name = name
end
def eat(food)
# return "that's not food!" unless food.respond_to?(:edible?)
@hungry = false
end
def shit
@hungry = true
end
def to_s
"Hi, I'm #{@name}"
end
end
class BedAndBreakfast
def self.feed(human, food)
human.eat(food)
end
end
bob = Human.new("Bob")
p bob
puts "am I hungry? #{bob.hungry}"
# bnb = BedAndBreakfast.new
BedAndBreakfast.feed(bob, Human.new)
puts "am I still hungry? #{bob.hungry}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment