aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/inflector/methods.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/inflector/methods.rb')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index 48296841aa..274dc90eff 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -203,7 +203,19 @@ module ActiveSupport
names.shift if names.empty? || names.first.empty?
names.inject(Object) do |constant, name|
- constant.const_get(name, false)
+ candidate = constant.const_get(name)
+ if constant.const_defined?(name, false) || !Object.const_defined?(name)
+ candidate
+ else
+ # Go down the ancestors to check it it's owned
+ # directly before we reach Object or the end of ancestors.
+ constant.ancestors.each do |ancestor|
+ break if ancestor == Object
+ return candidate if ancestor.const_defined?(name, false)
+ end
+ # owner is in Object, so raise
+ constant.const_get(name, false)
+ end
end
end