aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module/introspection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/module/introspection.rb')
-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