Created
October 28, 2013 16:04
-
-
Save meaganewaller/7199596 to your computer and use it in GitHub Desktop.
animalinheritance
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 Mammal | |
def breathe | |
puts "inhale and exhale" | |
end | |
end | |
class Cat < Mammal | |
def speak | |
puts "meow" | |
end | |
end | |
class Dog < Mammal | |
def speak | |
puts "bark" | |
end | |
end | |
class Cow < Mammal | |
def speak | |
puts "moo" | |
end | |
end | |
class Horse < Mammale | |
def speak | |
puts "neigh" | |
end | |
end | |
cat = Cat.new | |
cat.speak #=> "meow" | |
cat.breathe #=> "inhale and exhale" | |
dog = Dog.new | |
dog.speak #=> "bark" | |
dog.breathe #=> "inhale and exhale" | |
cow = Cow.new | |
cow.speak #=> "moo" | |
cow.breathe #=> "inhale and exhale" | |
horse = Horse.new | |
horse.speak #=> "neigh" | |
horse.breathe #=> "inhale and exhale" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment