aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-02-12 19:06:07 +0100
committerXavier Noria <fxn@hashref.com>2010-02-12 19:06:07 +0100
commit50b2a5d8cac95ac07979518478d2c4d37f33458a (patch)
treed43908b71016f3f581162869079cdc9135ec3d16 /railties/guides/source/active_support_core_extensions.textile
parent739b8a1638e1a6b40a906cca926764e1aad1d127 (diff)
downloadrails-50b2a5d8cac95ac07979518478d2c4d37f33458a.tar.gz
rails-50b2a5d8cac95ac07979518478d2c4d37f33458a.tar.bz2
rails-50b2a5d8cac95ac07979518478d2c4d37f33458a.zip
AS guide: documents Module#reachable?
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile38
1 files changed, 38 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index 3890341d13..7af89a6d24 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -849,6 +849,44 @@ 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
+
+A named module is reachable if it is stored in its correspoding constant. It means you can reach the module object via the constant.
+
+That is what ordinarily happens, if a module is called "M", the +M+ constant exists and holds it:
+
+<ruby>
+module M
+end
+
+M.reachable? # => true
+</ruby>
+
+But since constants and modules are indeed kind of decoupled, module objects can become unreachable:
+
+<ruby>
+module M
+end
+
+orphan = Object.send(:remove_const, :M)
+
+# The module object is orphan now but it still has a name.
+orphan.name # => "M"
+
+# You cannot reach it via the constant M because it does not even exist.
+orphan.reachable? # => false
+
+# Let's define a module called "M" again.
+module M
+end
+
+# The constant M exists now again, and it stores a module
+# object called "M", but it is a new instance.
+orphan.reachable? # => false
+</ruby>
+
+NOTE: Defined in +active_support/core_ext/module/reachable.rb+.
+
h3. Extensions to +Class+
h4. Class Attributes