且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用" ::"而不是“模块..."用于Ruby名称空间

更新时间:2023-09-29 09:46:46

如果使用class Foo::Bar,但尚未定义Foo模块,则会引发异常,而module Foo; class Bar方法将定义Foo(如果尚未定义的话).

If you use class Foo::Bar, but the Foo module hasn't been defined yet, an exception will be raised, whereas the module Foo; class Bar method will define Foo if it hasn't been defined yet.

也可以使用块格式在以下范围内定义多个类:

Also, with the block format, you could define multiple classes within:

module Foo
  class Bar; end
  class Baz; end
end