From 99e9a733c8852f4ff065f2ede9c9cd03475411a2 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Fri, 4 May 2012 23:57:11 -0400 Subject: Make constantize look down the ancestor chain (excluding Object) --- activesupport/lib/active_support/inflector/methods.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') 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 -- cgit v1.2.3