Skip to content

Instantly share code, notes, and snippets.

@Icelle
Created December 4, 2013 14:10
Show Gist options
  • Save Icelle/7787984 to your computer and use it in GitHub Desktop.
Save Icelle/7787984 to your computer and use it in GitHub Desktop.
Write a set of classes that represent a set of animals. There should be a Duck, Cat, and Dog instance that all implement an emote (**hint**: what sound does a duck make?) and a eat method. A constructor that takes a name as an argument should be defined elsewhere.
class Animal
attr_reader :name
def initialize(name)
@name
end
end
class Duck < Animal
def emote
"#{@name}'s quack"
end
def eat
"#{@name} eats corn"
end
end
class Dog < Animal
def emote
"#{@name}'s bark"
end
def eat
"#{@name} eats bone"
end
end
class Cat < Animal
def emote
"#{@name}'s meow"
end
def eat
"#{@name} eats fish"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment