aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/source/active_support_core_extensions.textile
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-02-07 00:20:46 +0100
committerXavier Noria <fxn@hashref.com>2010-02-07 00:20:46 +0100
commitf465a7abc7635bdf872e6ff7041f51f6e710c42f (patch)
treee3f3d90fec845813cf5d3b9047dd5c0a3c28ae7f /railties/guides/source/active_support_core_extensions.textile
parent81535d0fd2c5d9cb489c5fbefe8b949c0a560fa2 (diff)
downloadrails-f465a7abc7635bdf872e6ff7041f51f6e710c42f.tar.gz
rails-f465a7abc7635bdf872e6ff7041f51f6e710c42f.tar.bz2
rails-f465a7abc7635bdf872e6ff7041f51f6e710c42f.zip
AS guide: documents Module#local_constants and Module#local_constant_names
Diffstat (limited to 'railties/guides/source/active_support_core_extensions.textile')
-rw-r--r--railties/guides/source/active_support_core_extensions.textile24
1 files changed, 24 insertions, 0 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile
index ec71bc91b5..ed2b41af86 100644
--- a/railties/guides/source/active_support_core_extensions.textile
+++ b/railties/guides/source/active_support_core_extensions.textile
@@ -767,6 +767,30 @@ M.parents # => [X::Y, X, Object]
NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
+h4. Constants
+
+The method +local_constants+ returns the names of the constants that have been defined in the receiver module:
+
+<ruby>
+module X
+ X1 = 1
+ X2 = 2
+ module Y
+ Y1 = :y1
+ X1 = :overrides_X1_above
+ end
+end
+
+X.local_constants # => ["X2", "X1", "Y"], assumes Ruby 1.8
+X::Y.local_constants # => ["X1", "Y1"], assumes Ruby 1.8
+</ruby>
+
+The names are returned as strings in Ruby 1.8, and as symbols in Ruby 1.9. The method +local_constant_names+ returns always strings.
+
+WARNING: This method is exact if running under Ruby 1.9. In previous versions it may miss some constants if their value in some ancestor stores the exact same object than in the receiver.
+
+NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
+
h3. Extensions to +Class+
h4. Class Attributes