Given the following Hash hash with keys as symbols and values as arrays:
hash
#=> {:stage_item=>[:stage_batch_id, :potential_item_id], :item=>[:id, :size, :color, :status, :price_sold, :sold_at], :style=>[:wholesale_price, :retail_price, :type, :name]}
How do I get an array with of just the values (arrays) added together?
I know I can use #each_with_object and #flatten:
hash.each_with_object([]) { |(k, v), array| array << v }.flatten
#=> [:stage_batch_id, :potential_item_id, :id, :size, :color, :status, :price_sold, :sold_at, :wholesale_price, :retail_price, :type, :name]
But I was expecting just #each_with_object to work:
hash.each_with_object([]) { |(k, v), array| array += v }
#=> []
I though the point of each with object is it keeps track of the accumulator (named array in this case), so I can += it like in the following example:
arr = [1,2,3]
#=> [1, 2, 3]
arr += [4]
#=> [1, 2, 3, 4]
What am I missing?