details = [{:amount=>"5.95", :subtotal=>"11.90", :menu_label=>"Grommets", :qty=>"2"},
{:amount=>"1.25", :subtotal=>"11.25", :menu_label=>"Stuff", :qty=>"9"},
{:amount=>"33.95", :subtotal=>"169.75", :menu_label=>"More Stuff", :qty=>"5"},
{:amount=>"80.00", :subtotal=>"2160.00", :menu_label=>"HTML Markup", :qty=>"27"}]
Refactorings
No refactoring yet !
Tj Holowaychuk
August 4, 2009, August 04, 2009 02:16, permalink
details.map { |hash| hash[:subtotal] }
Alec Leitner
August 4, 2009, August 04, 2009 02:16, permalink
is this what you want?
details.map{|x| x[:subtotal]}
Chip Castle
August 4, 2009, August 04, 2009 13:54, permalink
Perfect! Exactly what I needed. Thanks!
I would like to create an array from the details variable below that contains only the values of the subtotals below. In other words, I would like to have this when all is said and done:
subtotals = ["11.90", "11.25", "169.75", "2160.00"]