Skip to content

Commit

Permalink
AS guide: documents methods related to a module's parent(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Feb 6, 2010
1 parent e4945b1 commit f3e41e0
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions railties/guides/source/active_support_core_extensions.textile
Expand Up @@ -700,6 +700,73 @@ end

NOTE: Defined in +active_support/core_ext/module/delegation+.

h4. Parents

h5. +parent+

The +parent+ method on a nested named module returns the module that contains its corresponding constant:

<ruby>
module X
module Y
module Z
end
end
end
M = X::Y::Z

X::Y::Z.parent # => X::Y
M.parent # => X::Y
</ruby>

If the module is anonymous or belongs to the top-level, +parent+ returns +Object+.

WARNING: Note that in that case +parent_name+ returns +nil+.

NOTE: Defined in +active_support/core_ext/module/introspection.rb+.

h5. +parent_name+

The +parent_name+ method on a nested named module returns the fully-qualified name of the module that contains its corresponding constant:

<ruby>
module X
module Y
module Z
end
end
end
M = X::Y::Z

X::Y::Z.parent_name # => "X::Y"
M.parent_name # => "X::Y"
</ruby>

For top-level or anonymous modules +parent_name+ returns +nil+.

WARNING: Note that in that case +parent+ returns +Object+.

NOTE: Defined in +active_support/core_ext/module/introspection.rb+.

h5. +parents+

The method +parents+ calls +parent+ on the receiver and upwards until +Object+ is reached. The chain is returned in an array, from bottom to top:

<ruby>
module X
module Y
module Z
end
end
end
M = X::Y::Z

X::Y::Z.parents # => [X::Y, X, Object]
M.parents # => [X::Y, X, Object]
</ruby>

NOTE: Defined in +active_support/core_ext/module/introspection.rb+.

h3. Extensions to +Class+

h4. Class Attributes
Expand Down

0 comments on commit f3e41e0

Please sign in to comment.