From 77bf78b3b78a41d4f2f6e733f5c9c00608c0adba Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 12 Feb 2010 20:52:00 +0100 Subject: AS guide: documents Module#anonymous? --- .../source/active_support_core_extensions.textile | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index 7af89a6d24..ce87919b89 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/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: + + +module M +end +M.name # => "M" + +N = Module.new +N.name # => "N" + +Module.new.name # => "" in 1.8, nil in 1.9 + + +You can check whether a module has a name with the predicate +anonymous?+: + + +module M +end +M.anonymous? # => false + +Module.new.anonymous? # => true + + +Note that being unreachable does not imply being anonymous: + + +module M +end + +m = Object.send(:remove_const, :M) + +m.reachable? # => false +m.anonymous? # => false + + +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 -- cgit v1.2.3