Skip to content

Instantly share code, notes, and snippets.

@metacritical
Created August 30, 2011 21:18
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 metacritical/1182072 to your computer and use it in GitHub Desktop.
Save metacritical/1182072 to your computer and use it in GitHub Desktop.
My Doubts in ruby Inheritance let the Cat help us out.
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