From f465a7abc7635bdf872e6ff7041f51f6e710c42f Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sun, 7 Feb 2010 00:20:46 +0100 Subject: AS guide: documents Module#local_constants and Module#local_constant_names --- .../source/active_support_core_extensions.textile | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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: + + +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 + + +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 -- cgit v1.2.3