Skip to content

Commit

Permalink
AS guide: documents Module#anonymous?
Browse files Browse the repository at this point in the history
  • Loading branch information
fxn committed Feb 12, 2010
1 parent 50b2a5d commit 77bf78b
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion railties/guides/source/active_support_core_extensions.textile
Expand Up @@ -849,7 +849,7 @@ The method receives the name of an action, and a +:with+ option with code. The c

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

h4. Reachable Modules
h4. Reachable

A named module is reachable if it is stored in its correspoding constant. It means you can reach the module object via the constant.

Expand Down Expand Up @@ -887,6 +887,47 @@ orphan.reachable? # => false

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

h4. Anonymous

A module may or may not have a name:

<ruby>
module M
end
M.name # => "M"

N = Module.new
N.name # => "N"

Module.new.name # => "" in 1.8, nil in 1.9
</ruby>

You can check whether a module has a name with the predicate +anonymous?+:

<ruby>
module M
end
M.anonymous? # => false

Module.new.anonymous? # => true
</ruby>

Note that being unreachable does not imply being anonymous:

<ruby>
module M
end

m = Object.send(:remove_const, :M)

m.reachable? # => false
m.anonymous? # => false
</ruby>

though an anonymous module is unreachable by definition.

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

h3. Extensions to +Class+

h4. Class Attributes
Expand Down

0 comments on commit 77bf78b

Please sign in to comment.