Skip to content

Instantly share code, notes, and snippets.

@szankowski
Last active August 29, 2015 14:23
Show Gist options
  • Save szankowski/e46eda9ad5554076e192 to your computer and use it in GitHub Desktop.
Save szankowski/e46eda9ad5554076e192 to your computer and use it in GitHub Desktop.
Classical Inheritence (Mini Exercise)
class Animal
attr_accessor :name, :num_legs, :warm_blood
def initialize(name, num_legs, warm_blood)
@name = name
@num_legs = num_legs
@warm_blood = warm_blood
end
end
###module
module Flight
# @airspeed_velocity = airspeed_velocity
def fly
puts "I can fly!"
end
end
##
class Mammal < Animal
def initialize(name, num_legs, sun_glasses)
super(name, num_legs, true )
@sun_glasses = sun_glasses
end
end
class Amphibian < Animal
end
class Primate < Mammal
end
#
class Frog < Amphibian
end
class Bat < Mammal
include Flight
def initialize(name)
super(name, 2, "Okley")
end
end
class Parrot < Animal
include Flight
def initialize(name)
super(name, 2, true)
end
end
class Chimpanzee < Mammal
end
require_relative "animals.rb"
# monkey = Primate.new("bob", 2, true)
# puts monkey.num_legs
# puts monkey.warm_blood
# chimp = Primate.new
# puts chimp.num_legs
# cat = Mammal.new("kit", 2)
# puts cat.warm_blood
monkey = Mammal.new("Telonius", 2, "rayban")
puts monkey.name
pirate = Parrot.new("Polly")
pirate.fly
batman = Bat.new("Bat-man")
batman.fly
puts batman.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment