Does Ruby provide the namespace path, e.g. something like [:A,:B] for class A::B::C?

醉酒当歌 提交于 2020-01-06 14:57:19

问题


Is the following possible?

puts A::B::C.new.namespace_path # => [:A,:B], or even [A,B]

回答1:


I think maybe #ancestors is what you're looking for.

So A::B::C.ancestors

or you may just want to self.class.to_s.split("::")



来源:https://stackoverflow.com/questions/3313473/does-ruby-provide-the-namespace-path-e-g-something-like-a-b-for-class-ab

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