diff options
author | Xavier Noria <fxn@hashref.com> | 2010-02-12 20:52:00 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-02-12 20:52:00 +0100 |
commit | 77bf78b3b78a41d4f2f6e733f5c9c00608c0adba (patch) | |
tree | b0c09ef8f51a341ab36964b0fa9a41edac0784a5 /railties/guides/source | |
parent | 50b2a5d8cac95ac07979518478d2c4d37f33458a (diff) | |
download | rails-77bf78b3b78a41d4f2f6e733f5c9c00608c0adba.tar.gz rails-77bf78b3b78a41d4f2f6e733f5c9c00608c0adba.tar.bz2 rails-77bf78b3b78a41d4f2f6e733f5c9c00608c0adba.zip |
AS guide: documents Module#anonymous?
Diffstat (limited to 'railties/guides/source')
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 43 |
1 files changed, 42 insertions, 1 deletions
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: + +<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 |