Sha256: 152d2a96075a2c1eef16d97d644f6613ae9f7551f6421d7b786f00f9d46b9997
Contents?: true
Size: 524 Bytes
Versions: 17
Compression:
Stored size: 524 Bytes
Contents
class Module def class_alias_method(to, from) # https://tieba.baidu.com/p/5535445605?red_tag=0735709674 贴吧大神给出的方案 # 类方法可以看做singleton class(单例类)的实例方法,下面两个方法都可以,上面这个方式也适用于早期的ruby版本 (class << self;self;end).send(:alias_method, to, from) # self.singleton_class.send(:alias_method, to, from) end def class_attr_accessor(symbol) self.class.send(:attr_accessor, symbol) end end
Version data entries
17 entries across 17 versions & 2 rubygems