I defined methods specific_data1
and specific_data2
in meta class, and expected these methods belong to the singleton class:
class User
def User.specific_data1
"user specific data defined on user"
end
class << self
def specific_data2
"user specific data defined in meta class"
end
end
end
But neither of the methods is found in:
User.singleton_class.methods
Please help me understand what singleton_method
on User
class is and how it is useful.
Object#methods
returns the methods of that object. Methods defined in a class aren't methods of that class object, they are methods of that class's instances.This has nothing to do with singleton classes, it's true for all classes:
Here's how that works with your example: