Skip to content

Instantly share code, notes, and snippets.

@ashleytbasinger
Created September 4, 2013 02:06
Show Gist options
  • Save ashleytbasinger/226338a45f59530b5181 to your computer and use it in GitHub Desktop.
Save ashleytbasinger/226338a45f59530b5181 to your computer and use it in GitHub Desktop.
inheritance exercise
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