Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

AS guide: documents Module#anonymous?

  • Loading branch information...
commit 77bf78b3b78a41d4f2f6e733f5c9c00608c0adba 1 parent 50b2a5d
@fxn fxn authored
Showing with 42 additions and 1 deletion.
  1. +42 −1 railties/guides/source/active_support_core_extensions.textile
View
43 railties/guides/source/active_support_core_extensions.textile
@@ -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.
@@ -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

0 comments on commit 77bf78b

Please sign in to comment.
Something went wrong with that request. Please try again.