什么是这个双结肠::?例如Foo::Bar.
我找到了一个定义:
它
::是一元运算符,允许:从类或模块外部的任何位置访问类或模块中定义的常量,实例方法和类方法.
如果您可以使用::暴露任何东西,范围(私人,受保护)有什么用处?
我有这样的代码.
class User < ActiveRecord::Base
end
module Foo
class User
end
end
module Foo
class DoesSomethingWithActiveRecordUser
def initialize user_id
User.find(user_id)
end
end
end
Run Code Online (Sandbox Code Playgroud)
如果我打电话,Foo::DoesSomethingWithActiveRecordUser.new(1)我会收到一条错误信息undefined method 'find' for Foo::User.
如何从内部呼叫ActiveRecord用户Foo?
谢谢.