From dc604b43a0566416a9f638f77ea24d90fbc377d5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 4 Jan 2008 03:25:20 +0000 Subject: Ruby 1.9: Module#local_constants can now just use constants(false). Closes #10648 [Xavier Noria] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8555 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../core_ext/module/introspection.rb | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/core_ext/module/introspection.rb b/activesupport/lib/active_support/core_ext/module/introspection.rb index 7e4d8e44fc..ddc9297b95 100644 --- a/activesupport/lib/active_support/core_ext/module/introspection.rb +++ b/activesupport/lib/active_support/core_ext/module/introspection.rb @@ -5,7 +5,7 @@ class Module parent_name = name.split('::')[0..-2] * '::' parent_name.empty? ? Object : parent_name.constantize end - + # Return all the parents of this module, ordered from nested outwards. The # receiver is not contained within the result. def parents @@ -18,18 +18,27 @@ class Module parents << Object unless parents.include? Object parents end - - # Return the constants that have been defined locally by this object and not - # in an ancestor. This method may miss some constants if their definition in - # the ancestor is identical to their definition in the receiver. - def local_constants - inherited = {} - ancestors.each do |anc| - next if anc == self - anc.constants.each { |const| inherited[const] = anc.const_get(const) } + + if RUBY_VERSION < '1.9' + # Return the constants that have been defined locally by this object and + # not in an ancestor. This method is exact if running under Ruby 1.9. In + # previous versions it may miss some constants if their definition in some + # ancestor is identical to their definition in the receiver. + def local_constants + inherited = {} + + ancestors.each do |anc| + next if anc == self + anc.constants.each { |const| inherited[const] = anc.const_get(const) } + end + + constants.select do |const| + !inherited.key?(const) || inherited[const].object_id != const_get(const).object_id + end end - constants.select do |const| - ! inherited.key?(const) || inherited[const].object_id != const_get(const).object_id + else + def local_constants #:nodoc: + constants(false) end end -- cgit v1.2.3