I have an array with hashes in it. If they have the same key I just want to add its value.
@receivers << result
@receivers
=> [{:email=>"[email protected]", :amount=>10.00}]
result
=> {:email=>"[email protected]", :amount=>7.00}
I want the result of above to look like this
[{:email=>"[email protected]", :amount=>17.00}]
Does anyone know how to do this?
Here is the the entire method
def receivers
@receivers = []
orders.each do |order|
product_email = order.product.user.paypal_email
outfit_email = order.outfit_user.paypal_email
if order.user_owns_outfit?
result = { email: product_email, amount: amount(order.total_price) }
else
result = { email: product_email, amount: amount(order.total_price, 0.9),
email: outfit_email, amount: amount(order.total_price, 0.1) }
end
@receivers << result
end
end
:emailvalue?