【发布时间】:2017-02-14 16:14:07
【问题描述】:
这个方法是返回任意对象的特征类:
class Object
def eigenclass
class << self; self; end
end
end
字符串示例:
"abc".eigenclass # => #<Class:#<String:0x331df0>>
数组:
[1, 2].eigenclass # => #<Class:#<Array:0x0000000065d218>>
但使用 Fixnum:
1.eigenclass # => TypeError: can't define singleton
为什么?
【问题讨论】:
-
我认为this 可能会对您有所帮助。请通过它。
标签: ruby eigenclass