diff options
author | Jorge Bejar <jorge@wyeworks.com> | 2012-04-12 00:41:25 -0300 |
---|---|---|
committer | Jorge Bejar <jorge@wyeworks.com> | 2012-04-18 10:57:46 -0300 |
commit | 7dc03cfd768b730933c5d4331b8202237f2fe10f (patch) | |
tree | 2bba50a5da2fc8df3da1c6062ccfb1effa00a721 /activerecord/lib | |
parent | 7ecd6a731bd60665bc6de94095137f0b2c4ada2a (diff) | |
download | rails-7dc03cfd768b730933c5d4331b8202237f2fe10f.tar.gz rails-7dc03cfd768b730933c5d4331b8202237f2fe10f.tar.bz2 rails-7dc03cfd768b730933c5d4331b8202237f2fe10f.zip |
Define array methods in ActiveRecord::Associations::CollectionProxy
if they are not defined or delegated.
In this way, we have a performance boost invoking some array methods
which are not defined in CollectionAssociation.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/collection_proxy.rb | 13 |
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 |