Created
March 9, 2015 21:13
-
-
Save Andsbf/347c0098a1b4095290b3 to your computer and use it in GitHub Desktop.
Classical Inheritence (Mini Exercise)
This file contains hidden or 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
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