myhouse myhouse - 2 months ago 9
Ruby Question

How can I extract just the ids from an array of hashes?

I want to iterate over this data to extract the value of the ids:

[ {:id => 3, :quantity => 5 }, { :id => 4, :quantity => 3 } ]

Answer
[ {:id => 3, :quantity => 5 }, { :id => 4, :quantity => 3 } ].each do |hash|
  puts hash[:id]
end

This will puts each id value on the screen. You can do what you need to do from there.