tags:

views:

43

answers:

2

I am having trouble including a module in a namespaced class. The example below throws the error uninitialized constant Bar::Foo::Baz (NameError). What basic piece of Ruby knowledge am I missing 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
A: 

include ::Foo::Baz

vladr
+3  A: 

Use :: to force the lookup to the top level only:

module Bar
  class Foo
    include ::Foo::Baz
  end
end
molf
Thank you, sir.
hakanensari