Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

AS guide: documents Module#local_constants and Module#local_constant_…

…names
  • Loading branch information...
commit f465a7abc7635bdf872e6ff7041f51f6e710c42f 1 parent 81535d0
@fxn fxn authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 railties/guides/source/active_support_core_extensions.textile
View
24 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
Please sign in to comment.
Something went wrong with that request. Please try again.