diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-17 14:50:24 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-05-17 14:50:24 -0600 |
commit | 113f56d31d5e0fb60a69ab995b8f51705de7213d (patch) | |
tree | 42aa36c259927283e9085fb464831c82358d1879 | |
parent | 7359f8190d0ac97db077096796bdc582dffa90d8 (diff) | |
download | rails-113f56d31d5e0fb60a69ab995b8f51705de7213d.tar.gz rails-113f56d31d5e0fb60a69ab995b8f51705de7213d.tar.bz2 rails-113f56d31d5e0fb60a69ab995b8f51705de7213d.zip |
Use destructured arguments when looping through pairs
Minor refactoring of looping behavior for aggregation
-rw-r--r-- | activerecord/lib/active_record/aggregations.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index 0d5313956b..45c275a017 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -230,8 +230,8 @@ module ActiveRecord private def reader_method(name, class_name, mapping, allow_nil, constructor) define_method(name) do - if @aggregation_cache[name].nil? && (!allow_nil || mapping.any? {|pair| !read_attribute(pair.first).nil? }) - attrs = mapping.collect {|pair| read_attribute(pair.first)} + if @aggregation_cache[name].nil? && (!allow_nil || mapping.any? {|key, _| !read_attribute(key).nil? }) + attrs = mapping.collect {|key, _| read_attribute(key)} object = constructor.respond_to?(:call) ? constructor.call(*attrs) : class_name.constantize.send(constructor, *attrs) @@ -249,10 +249,10 @@ module ActiveRecord end if part.nil? && allow_nil - mapping.each { |pair| self[pair.first] = nil } + mapping.each { |key, _| self[key] = nil } @aggregation_cache[name] = nil else - mapping.each { |pair| self[pair.first] = part.send(pair.last) } + mapping.each { |key, value| self[key] = part.send(value) } @aggregation_cache[name] = part.freeze end end |