1

If I have the following modules:

module Foo
end

module Foo::Bar
  def print
    puts "something"
  end
end

Why does this usage style work?

module Foo
  class Baz
    include Bar
  end
end

Foo::Baz.new.print

But this usage style errors with "uninitialized constant Foo::Baz::Bar (NameError)"?

class Foo::Baz
  include Bar
end

Foo::Baz.new.print

Isn't the second usage case just shorthand for the first one?

ayushn21
  • 305
  • 2
  • 7
  • 1
    Does this answer your question? [Why doesn't Ruby find classes in a higher scope when module is specified using ::?](https://stackoverflow.com/questions/34338131/why-doesnt-ruby-find-classes-in-a-higher-scope-when-module-is-specified-using) – engineersmnky Sep 30 '20 at 14:25
  • 1
    Yes, thanks @engineersmnky! :) – ayushn21 Sep 30 '20 at 14:42

0 Answers0