ruby中的::类做什么?
可能重复:ruby中的::类做什么?,ruby,Ruby,可能重复: 请原谅我的懒惰。我试着猜。我不确定双精度“::Logger”在这种情况下起什么作用 它似乎正在初始化对象并将其分配到不在其范围内的变量上?第25行由{begin/end}块包装,并分配给@logger,就像路径中定义嵌套目录的/一样,:访问嵌套类 与前导的/类似,前导的:表示从树的最顶端开始。它开始在全局范围内搜索常量 # Bar declared in global scope class Bar end # Foo declared in global scope
请原谅我的懒惰。我试着猜。我不确定双精度“::Logger”在这种情况下起什么作用
它似乎正在初始化对象并将其分配到不在其范围内的变量上?第25行由{begin/end}块包装,并分配给@logger,就像路径中定义嵌套目录的
/
一样,:
访问嵌套类
与前导的/
类似,前导的:
表示从树的最顶端开始。它开始在全局范围内搜索常量
# Bar declared in global scope
class Bar
end
# Foo declared in global scope
class Foo
# A different class named Bar declared in the scope of Foo, not global
class Bar
end
Bar #=> refers to Foo::Bar, that is class Bar declared within Foo
::Bar #=> refers to outer global scope class named Bar
end
就像路径中的
/
定义嵌套目录一样,:
访问嵌套类
与前导的/
类似,前导的:
表示从树的最顶端开始。它开始在全局范围内搜索常量
# Bar declared in global scope
class Bar
end
# Foo declared in global scope
class Foo
# A different class named Bar declared in the scope of Foo, not global
class Bar
end
Bar #=> refers to Foo::Bar, that is class Bar declared within Foo
::Bar #=> refers to outer global scope class named Bar
end
::Logger
正在引用顶级命名空间中的Logger
类。@MatheusMoreira:是,确实:)::Logger
正在引用顶级命名空间中的Logger
类。@MatheusMoreira:是,确实:)