diff options
author | Xavier Noria <fxn@hashref.com> | 2012-01-12 12:17:24 -0800 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2012-01-12 12:17:35 -0800 |
commit | 04df7bb02c8a267ec7cd1c20ba20a49a24cffb2f (patch) | |
tree | feeaaada1aef0e1055bd1626274dfd7a49d0e29d /activesupport | |
parent | 3c64548859a9e778bc6f5b0bdb796dc1b5136c3d (diff) | |
download | rails-04df7bb02c8a267ec7cd1c20ba20a49a24cffb2f.tar.gz rails-04df7bb02c8a267ec7cd1c20ba20a49a24cffb2f.tar.bz2 rails-04df7bb02c8a267ec7cd1c20ba20a49a24cffb2f.zip |
deprecates Module#local_constant_names
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 3 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/module/introspection.rb | 14 | ||||
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 4 | ||||
-rw-r--r-- | activesupport/test/core_ext/module_test.rb | 6 |
4 files changed, 23 insertions, 4 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index c19d4c7b32..c339e93808 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,8 @@ ## Rails 4.0.0 (unreleased) ## +* Deprecates the compatibility method Module#local_constant_names, + use Module#local_constants instead (which returns symbols). *fxn* + * Deletes the compatibility method Module#method_names, use Module#methods from now on (which returns symbols). *fxn* diff --git a/activesupport/lib/active_support/core_ext/module/introspection.rb b/activesupport/lib/active_support/core_ext/module/introspection.rb index 1893a9cfa6..743db47bac 100644 --- a/activesupport/lib/active_support/core_ext/module/introspection.rb +++ b/activesupport/lib/active_support/core_ext/module/introspection.rb @@ -61,9 +61,19 @@ class Module constants(false) end - # Returns the names of the constants defined locally rather than the - # constants themselves. See <tt>local_constants</tt>. + # *DEPRECATED*: Use +local_constants+ instead. + # + # Returns the names of the constants defined locally as strings. + # + # module M + # X = 1 + # end + # M.local_constant_names # => ["X"] + # + # This method is useful for forward compatibility, since Ruby 1.8 returns + # constant names as strings, whereas 1.9 returns them as symbols. def local_constant_names + ActiveSupport::Deprecation.warn('Module#local_constant_names is deprecated, use Module#local_constants instead', caller) local_constants.map { |c| c.to_s } end end diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index e121e452a3..2c5950edf5 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -105,7 +105,7 @@ module ActiveSupport #:nodoc: next unless mod.is_a?(Module) # Get a list of the constants that were added - new_constants = mod.local_constant_names - original_constants + new_constants = mod.local_constants - original_constants # self[namespace] returns an Array of the constants that are being evaluated # for that namespace. For instance, if parent.rb requires child.rb, the first @@ -133,7 +133,7 @@ module ActiveSupport #:nodoc: namespaces.map do |namespace| module_name = Dependencies.to_constant_name(namespace) original_constants = Dependencies.qualified_const_defined?(module_name) ? - Inflector.constantize(module_name).local_constant_names : [] + Inflector.constantize(module_name).local_constants : [] watching << module_name @stack[module_name] << original_constants diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 950ef82a3c..09ca4e7296 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -212,6 +212,12 @@ class ModuleTest < ActiveSupport::TestCase def test_local_constants assert_equal %w(Constant1 Constant3), Ab.local_constants.sort.map(&:to_s) end + + def test_local_constant_names + ActiveSupport::Deprecation.silence do + assert_equal %w(Constant1 Constant3), Ab.local_constant_names + end + end end module BarMethodAliaser |