Created
August 30, 2011 21:18
-
-
Save metacritical/1182072 to your computer and use it in GitHub Desktop.
My Doubts in ruby Inheritance let the Cat help us out.
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 Cat | |
def self.speak # this is a class method | |
puts "Meow" | |
end | |
end | |
class Lion < Cat | |
def roar | |
puts "Roar Roar !!!!" #now this is just an ordinary method. | |
end | |
end | |
newcat = Lion.new | |
puts newcat.methods.include?("speak") #this produces false | |
puts newcat.methods.include?("roar") #produces true | |
This means speak method is not present in newcat which is an instance of Lion and inherits from Cat. and speak is a class method in Cat. | |
"puts Cat.methods" produces a list of what ? | |
1) Class methods | |
2) Instance Methods | |
3) Protected Methods | |
4) Public Methods | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment