Skip to content

Instantly share code, notes, and snippets.

@meaganewaller
Created October 28, 2013 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meaganewaller/7199596 to your computer and use it in GitHub Desktop.
Save meaganewaller/7199596 to your computer and use it in GitHub Desktop.
animalinheritance
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