类<Ruby中的自我成语什么class << self用红宝石做的?
3 回答
当年话下
TA贡献1890条经验 获得超9个赞
class << self
, Eigenclass
methods
实例方法 单例方法 类方法
class Foo def an_instance_method puts "I am an instance method" end def self.a_class_method puts "I am a class method" end endfoo = Foo.newdef foo.a_singleton_method puts "I am a singletone method"end
Eigenclass
class <<
):
foo = Foo.newclass << foo def a_singleton_method puts "I am a singleton method" endend
self
Foo
class Foo class << self def a_singleton_and_class_method puts "I am a singleton method for self and a class method for Foo" end endend
- 3 回答
- 0 关注
- 506 浏览
添加回答
举报
0/150
提交
取消