aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2012-08-19 23:50:34 +0200
committerXavier Noria <fxn@hashref.com>2012-08-19 23:55:54 +0200
commit937a8259219070251e0b46a9a456492e3bc4dc74 (patch)
treecd02aa5d42ae6574acb9e65aee85b0a651e3a069 /activesupport/lib
parent7a8aee08b610f6edbfe5be076dc14e5cdcf1355e (diff)
downloadrails-937a8259219070251e0b46a9a456492e3bc4dc74.tar.gz
rails-937a8259219070251e0b46a9a456492e3bc4dc74.tar.bz2
rails-937a8259219070251e0b46a9a456492e3bc4dc74.zip
removes the second argument of the AS const_missing hook
Ruby does not pass the nesting to const_missing (unfortunately). That second argument was there in case that changed, Yehuda sent a patch to MRI http://bugs.ruby-lang.org/issues/2740 but there is not much movement there and Matz told me in Amsterdam there was no immediate plan to pass the nesting. So let's go back to implement what happens now, and if in the future we get the nesting then we will adapt this. Double-checked this with Mr Katz.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/dependencies.rb30
1 files changed, 22 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index bb22357c9b..77cab6f08d 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -168,16 +168,30 @@ module ActiveSupport #:nodoc:
end
end
- def const_missing(const_name, nesting = nil)
+ def const_missing(const_name)
klass_name = name.presence || "Object"
- unless nesting
- # We'll assume that the nesting of Foo::Bar is ["Foo::Bar", "Foo"]
- # even though it might not be, such as in the case of
- # class Foo::Bar; Baz; end
- nesting = []
- klass_name.to_s.scan(/::|$/) { nesting.unshift $` }
- end
+ # Since Ruby does not pass the nesting at the point the unknown
+ # constant triggered the callback we cannot fully emulate constant
+ # name lookup and need to make a trade-off: we are going to assume
+ # that the nesting in the body of Foo::Bar is [Foo::Bar, Foo] even
+ # though it might not be. Counterexamples are
+ #
+ # class Foo::Bar
+ # Module.nesting # => [Foo::Bar]
+ # end
+ #
+ # or
+ #
+ # module M::N
+ # module S::T
+ # Module.nesting # => [S::T, M::N]
+ # end
+ # end
+ #
+ # for example.
+ nesting = []
+ klass_name.to_s.scan(/::|$/) { nesting.unshift $` }
# If there are multiple levels of nesting to search under, the top
# level is the one we want to report as the lookup fail.