我在命名空间类中包含模块时遇到问题.以下示例将引发错误uninitialized constant Bar::Foo::Baz (NameError).我在这里缺少什么基本的Ruby知识?
module Foo
module Baz
def hello
puts 'hello'
end
end
end
module Bar
class Foo
include Foo::Baz
end
end
foo = Bar::Foo.new
Run Code Online (Sandbox Code Playgroud)
使用::的查找强制仅顶层:
module Bar
class Foo
include ::Foo::Baz
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
176 次 |
| 最近记录: |