diff options
author | Mat Brown <mat@patch.com> | 2009-10-22 10:20:44 -0400 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-12-02 12:47:09 -0800 |
commit | 49e943c4f0ac3459bd53023167aaa08fc8e46733 (patch) | |
tree | caf1d785fa27bdaf3ba7744842ba4b95d554d8c2 /activerecord/lib/active_record | |
parent | 50c28e78c7aa40dc329facbe6131d657d5629bd4 (diff) | |
download | rails-49e943c4f0ac3459bd53023167aaa08fc8e46733.tar.gz rails-49e943c4f0ac3459bd53023167aaa08fc8e46733.tar.bz2 rails-49e943c4f0ac3459bd53023167aaa08fc8e46733.zip |
Fix instance_eval calls to association proxies
In the current stable, ActiveRecord::Associations::AssociationProxy#method_missing calls yield() if a block is given, causing the block to always be evaluated in its calling context. However, in the case of instance_eval, correct behavior requires that the block be passed directly to the @target, rather than being evaluated inside a different block. Incidentally, this also simplifies the code slightly.
[#3412 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/association_proxy.rb | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 7d8f4670fa..6ad1e06300 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -200,18 +200,14 @@ module ActiveRecord private # Forwards any missing method call to the \target. - def method_missing(method, *args) + def method_missing(method, *args, &block) if load_target unless @target.respond_to?(method) message = "undefined method `#{method.to_s}' for \"#{@target}\":#{@target.class.to_s}" raise NoMethodError, message end - if block_given? - @target.send(method, *args) { |*block_args| yield(*block_args) } - else - @target.send(method, *args) - end + @target.send(method, *args, &block) end end |