Skip to content

Commit

Permalink
Merge pull request #15160 from sgrif/sg-destructured-each
Browse files Browse the repository at this point in the history
Use destructured arguments when looping through pairs
  • Loading branch information
rafaelfranca committed May 19, 2014
2 parents d4cec31 + 113f56d commit 85b78fc
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions activerecord/lib/active_record/aggregations.rb
Expand Up @@ -230,8 +230,8 @@ def composed_of(part_id, options = {})
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)
Expand All @@ -249,10 +249,10 @@ def writer_method(name, class_name, mapping, allow_nil, converter)
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
Expand Down

0 comments on commit 85b78fc

Please sign in to comment.