问题
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