How to access the base namespace in Ruby?

后端 未结 2 715
北荒
北荒 2021-02-05 02:38

I\'m writing code in a namespace where the File module exists (inside another module)

And I need to access the ruby File class.

In php this could be done like th

相关标签:
2条回答
  • 2021-02-05 03:05
    ::File
    

    Prefixing with :: accesses the 'root' of the namespace tree.

    0 讨论(0)
  • 2021-02-05 03:07

    I'm not sure what you're asking, but if you are inside of module Foo and you reference class Bar, then ruby will look for Foo::Bar. To look just for Bar, you should reference ::Bar (of course, this Bar should be defined in "global" scope, outside of Foo).

    0 讨论(0)
提交回复
热议问题