在 Ruby 中,写法有区别吗class Foo::Bar
and module Foo; class Bar
用于命名空间?如果是这样,那又怎样?
如果你使用class Foo::Bar
,但是Foo
模块尚未定义,将会引发异常,而module Foo; class Bar
方法将定义Foo
如果尚未定义。
此外,使用块格式,您可以在以下位置定义多个类:
module Foo
class Bar; end
class Baz; end
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)