Skip to content

Instantly share code, notes, and snippets.

@Andsbf
Created March 9, 2015 21:13
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 Andsbf/347c0098a1b4095290b3 to your computer and use it in GitHub Desktop.
Save Andsbf/347c0098a1b4095290b3 to your computer and use it in GitHub Desktop.
Classical Inheritence (Mini Exercise)
require 'rspec'
RSpec.configure do |config|
config.color = true
end
#classes experiment!!!
module Flight
def fly
print("I'm #{self.class}, Sure I can fly")
end
end
class Animal
attr_accessor :name
def initialize name
@name = name
end
def warm_blooded?
self.kind_of?( Mammal ) || self.kind_of?( Bird )
end
end
class Mammal < Animal ; end
class Amphibian < Animal; end
class Bird < Animal
include Flight
end
class Primate < Mammal; end
class Frog < Amphibian; end
class Bat < Mammal
include Flight
end
class Parrot < Bird; end
class Chimpanzee < Primate; end
describe "#warm_blooded?" do
it "return true for Mammal or Bird subclasses" do
joe = Primate.new("Joe")
result = joe.warm_blooded?
result.should eq(true)
end
it "return False for not Mammal or Bird subclasses" do
joe = Frog.new("Joe")
result = joe.warm_blooded?
result.should eq(false)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment