【发布时间】:2015-09-05 09:11:11
【问题描述】:
我在元类中定义了方法specific_data1和specific_data2,并且期望这些方法属于单例类:
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
但是这两种方法都没有找到:
User.singleton_class.methods
请帮助我了解User 课程中的singleton_method 是什么以及它有什么用处。
【问题讨论】: