Created
May 5, 2015 01:12
-
-
Save laurenachoo/2fb4e5d7769c63bf7e57 to your computer and use it in GitHub Desktop.
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 | |
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