How to include a module in a class with names?

I'm having problems including a module in a class with names. In the example below, an uninitialized constant Bar::Foo::Baz (NameError) . What is the bulk of Ruby knowledge I don't see here?

 module Foo module Baz def hello puts 'hello' end end end module Bar class Foo include Foo::Baz end end foo = Bar::Foo.new 
+6
ruby
source share
2 answers

Use :: to force the search only at the top level:

 module Bar class Foo include ::Foo::Baz end end 
+7
source share

include ::Foo::Baz

0
source share

All Articles