Created
July 17, 2013 14:06
-
-
Save Papillard/6020841 to your computer and use it in GitHub Desktop.
simple taste of inheritance with desserts..
This file contains 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 Dessert | |
attr_accessor :name, :calories | |
def initialize(name, calories) | |
@name, @calories = name, calories | |
end | |
def healthy? | |
@calories < 200 | |
end | |
def delicious? | |
true | |
end | |
end | |
class JellyBean < Dessert | |
attr_accessor :flavor | |
def initialize(name, calories, flavor) | |
super( name, calories ) | |
@flavor = flavor | |
end | |
def delicious? | |
@flavor == "black licorice" ? false : super | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment