aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-01-04 03:25:20 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-01-04 03:25:20 +0000
commitdc604b43a0566416a9f638f77ea24d90fbc377d5 (patch)
tree7f84b09775ce0c82731fa5ea23296f1a2e1dbeea /activesupport
parentc36f8111a6e7f305adc8eac87ea006e2517b93df (diff)
downloadrails-dc604b43a0566416a9f638f77ea24d90fbc377d5.tar.gz
rails-dc604b43a0566416a9f638f77ea24d90fbc377d5.tar.bz2
rails-dc604b43a0566416a9f638f77ea24d90fbc377d5.zip
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
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/module/introspection.rb33
1 files changed, 21 insertions, 12 deletions
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