Created
September 4, 2013 02:06
-
-
Save ashleytbasinger/226338a45f59530b5181 to your computer and use it in GitHub Desktop.
inheritance exercise
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 Animal | |
def initialize(name) | |
@name = name | |
end | |
def eat(food) | |
puts "#{@name} the #{self.class} eats #{food}." | |
end | |
def emote | |
puts "Loud Noises!" | |
end | |
end | |
class Duck < Animal | |
def emote | |
puts "Quack!" | |
end | |
end | |
class Cat < Animal | |
def emote | |
puts "Meow!" | |
end | |
end | |
class Dog < Animal | |
def emote | |
puts "Woof!" | |
end | |
end | |
duck = Duck.new("Delicious") | |
cat = Cat.new("Osiris") | |
dog = Dog.new("Bear") | |
duck.emote | |
dog.emote | |
cat.emote | |
duck.eat('junebugs') | |
dog.eat('everything') | |
cat.eat('birds') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment