Permalink
Browse files

Merge remote-tracking branch 'jmbejar/define_array_methods_collection…

…_proxy'
  • Loading branch information...
2 parents 8b941e9 + 7dc03cf commit 2a9763621c55dbef57ef0453ab24e13a81dd53c8 @jonleighton jonleighton committed Apr 25, 2012
Showing with 13 additions and 0 deletions.
  1. +13 −0 activerecord/lib/active_record/associations/collection_proxy.rb
@@ -126,6 +126,19 @@ def reload
proxy_association.reload
self
end
+
+ # Define array public methods because we know it should be invoked over
+ # the target, so we can have a performance improvement using those methods
+ # in association collections
+ Array.public_instance_methods.each do |m|
+ unless method_defined?(m)
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ def #{m}(*args, &block)
+ target.public_send(:#{m}, *args, &block) if load_target
+ end
+ RUBY
+ end
+ end
end
end
end

0 comments on commit 2a97636

Please sign in to comment.