aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-04-25 16:25:42 +0100
committerJon Leighton <j@jonathanleighton.com>2012-04-25 16:25:42 +0100
commit2a9763621c55dbef57ef0453ab24e13a81dd53c8 (patch)
tree6c21a2c5c8c783b5d761c1c5f9bdf4caf233c5a5 /activerecord/lib/active_record/associations
parent8b941e977c094bb2121f9eaef73f20392d20f581 (diff)
parent7dc03cfd768b730933c5d4331b8202237f2fe10f (diff)
downloadrails-2a9763621c55dbef57ef0453ab24e13a81dd53c8.tar.gz
rails-2a9763621c55dbef57ef0453ab24e13a81dd53c8.tar.bz2
rails-2a9763621c55dbef57ef0453ab24e13a81dd53c8.zip
Merge remote-tracking branch 'jmbejar/define_array_methods_collection_proxy'
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 5eda0387c4..44cbf473a1 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -126,6 +126,19 @@ module ActiveRecord
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