If I define a class-method in Ruby Object class, how do I get the name of a child class calling this method?

孤人 提交于 2019-12-11 12:24:36

问题


Example

def Object.const_missing(name)
  puts self.class
end
class A; end
A::B # => Class

How can I get A in Object#const_missing?


回答1:


def Object.const_missing(name)
  puts self
end


来源:https://stackoverflow.com/questions/3314108/if-i-define-a-class-method-in-ruby-object-class-how-do-i-get-the-name-of-a-chil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!