Need help understanding namespace rules-modules and classes


#1

I’m having a namespace collision and I think I need some basic
understanding of how Ruby is managing namespaces. I am 99% sure I know
which namespaces are colliding, but I’m not completely clear on how to
resolve it.

I have Module A (rubyful_soup.rb) which defines class Tag. It appears
that this Tag class is not defined inside of a module.

I have Module B (node.rb) which defines class Tag. It appears that this
Tag class is defined inside of a module called HTML.

However, I seem to be unable to avoid a “wrong number of arguments”
error when an attempt is made to instantiate Tag in node.rb, and I am
pretty sure that Tag from rubyful_soup.rb is interfering.

Here are my questions:

  1. If I define a class inside of a module, and then address that class
    by module_name::class_name, should that ensure that I will get that
    class? Is the namespace actually defined by the module names or not?

  2. Assuming that module::class is the correct way to address the class,
    then within a module, would I need to address my classes using
    module::class consistently or can I just use the class name in the
    module?

Can someone give me an example of how I could address having two
different classes of the same name in two different modules?

I’m just not understanding what the equivalent of the Java package
structure is in Ruby.

Thanks,
Wes