Ruby (and Rails) nested module syntax

Posted by brad on Stack Overflow See other posts from Stack Overflow or by brad
Published on 2010-05-19T19:44:36Z Indexed on 2010/05/19 21:40 UTC
Read the original article Hit count: 242

Filed under:
|
|

I'm wondering what the difference is between the following two modules

# First Example
module Parent
  module Child
  end
end

and

# Second Example
module Parent::Child
end

Using the 2nd method, it appears as though the Parent module must be previously defined, otherwise I get an 'uninitialized constant' error

Given this, what is the preferred way of defining modules such as this and then adding nested children with regards to syntax and file structure (ie. folders etc). Reference to a Rails way would be greatly appreciated.

Are these two examples for all intents and purposes equivalent?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about modules