class Person
def name
puts "Doharey"
end
end
puts Person.class #=> this out puts Class
puts Class.methods.count #=> 82 methods
puts Person.methods.count #=> 82 methods
In the above example a Person class is created which inherits from Class and both Person and Class has equal number of methods.
Now lets instantiate Person class
a = Person.new
puts a.methods.count #=> 42 methods
If a is an instance of Person then why are the number of methods less in a than Person. What happens ? how some methods go missing ? Are they not inherited in the first place ? If so how ?
are the instance methods and
are class methods. They do not share the same namespace. When you define
nameonPersonyou are defining an instance methods.Here I’ve defined a class method which also shows up in the method list.