Created
December 4, 2013 14:10
-
-
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.
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 | |
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