diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2012-05-04 23:57:11 -0400 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-05-19 15:47:35 +0100 |
commit | 99e9a733c8852f4ff065f2ede9c9cd03475411a2 (patch) | |
tree | f008edad42da92cb6c96a30edf346bf4e0b0c7fb /activesupport/lib/active_support/inflector | |
parent | 1551de3c04bf872423683926f92916abe2a49ad1 (diff) | |
download | rails-99e9a733c8852f4ff065f2ede9c9cd03475411a2.tar.gz rails-99e9a733c8852f4ff065f2ede9c9cd03475411a2.tar.bz2 rails-99e9a733c8852f4ff065f2ede9c9cd03475411a2.zip |
Make constantize look down the ancestor chain (excluding Object)
Diffstat (limited to 'activesupport/lib/active_support/inflector')
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 14 |
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 |