Skip to content

Instantly share code, notes, and snippets.

@laurenachoo
Created May 5, 2015 01:12
Show Gist options
  • Save laurenachoo/2fb4e5d7769c63bf7e57 to your computer and use it in GitHub Desktop.
Save laurenachoo/2fb4e5d7769c63bf7e57 to your computer and use it in GitHub Desktop.
class Animal
def initialize(name, food)
@name = name
@legs = 4
@food = food
end
def breathe
puts "This animal breathes."
end
def intro
puts "#@name eats #@food."
end
end
class Cat <Animal
def climbs
puts "I can climb a tree!"
end
end
class Dog < Animal
def fetch
puts "I can fetch a ball!"
end
end
class Bird < Animal
def initialize(name, food)
super(name, food)
@legs = 2
end
def fly
puts "I can fly!"
end
end
c = Cat.new("Meowchi", "mice")
d = Dog.new("Woofins", "bones")
b = Bird.new("Chirplet", "bird seed")
b.intro
b.breathe
b.fly
puts
c.intro
c.climbs
c.breathe
puts
d.intro
d.fetch
d.breathe
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment