aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/inflector
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2016-12-14 11:47:51 +0100
committerJean Boussier <jean.boussier@gmail.com>2016-12-14 14:25:43 +0100
commit11e05defecde965e0eb1929f1b0f1f992be39a6b (patch)
tree2743c8f2f18edf9aaf4bea170805fe080e216d89 /activesupport/lib/active_support/inflector
parente3e663f1dc40a5cfae9ec60e32f5372cd7f9885b (diff)
downloadrails-11e05defecde965e0eb1929f1b0f1f992be39a6b.tar.gz
rails-11e05defecde965e0eb1929f1b0f1f992be39a6b.tar.bz2
rails-11e05defecde965e0eb1929f1b0f1f992be39a6b.zip
Fix constantize edge case involving prepend, autoloading and name conflicts
In the following situation: ```ruby class Bar end module Baz end class Foo prepend Baz end class Foo::Bar end ``` Running `Inflector.constantize('Foo::Bar')` would blow up with a NameError. What is happening is that `constatize` was written before the introduction of prepend, and wrongly assume that `klass.ancestors.first == klass`. So it uses `klass.ancestors.inject` without arguments, as a result a prepended module is used in place of the actual class.
Diffstat (limited to 'activesupport/lib/active_support/inflector')
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index ef3df1240d..fa063af3f4 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -274,7 +274,7 @@ module ActiveSupport
# Go down the ancestors to check if it is owned directly. The check
# stops when we reach Object or the end of ancestors tree.
- constant = constant.ancestors.inject do |const, ancestor|
+ constant = constant.ancestors.inject(constant) do |const, ancestor|
break const if ancestor == Object
break ancestor if ancestor.const_defined?(name, false)
const