Created
October 18, 2012 02:49
-
-
Save BrianJoyce/3909601 to your computer and use it in GitHub Desktop.
classes fuck around
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 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