Skip to content

Instantly share code, notes, and snippets.

@Papillard
Created July 17, 2013 14:06
Show Gist options
  • Save Papillard/6020841 to your computer and use it in GitHub Desktop.
Save Papillard/6020841 to your computer and use it in GitHub Desktop.
simple taste of inheritance with desserts..
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