What is Ruby's double-colon `::`?

后端 未结 10 1994
南笙
南笙 2020-11-22 10:09

What is this double-colon ::? E.g. Foo::Bar.

I found a definition:

The :: is a unary operator that all

10条回答
  •  花落未央
    2020-11-22 10:47

    No, it is not to access every method, it is a "resolution" operator, that is, you use it to resolve the scope (or location you can say) of a constant/static symbol.

    For example in the first of your line, Rails use it to find the Base class inside the ActiveRecord.Module, in your second one it is used to locate the class method (static) of the Routes class, etc, etc.

    It is not used to expose anything, its used to "locate" stuff around your scopes.

    http://en.wikipedia.org/wiki/Scope_resolution_operator

提交回复
热议问题