[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Multiple values for the same key in a Hash

Gavin Kistner

10/12/2006 7:09:00 PM

> From: Dominic Son
> Yes, i was thinking your later suggestion, but how do i
> iterate through
> them..
>
> the price, and quanity come back too containated (ie : 1.995
> ) do i have
> to mess with a .split and reg exp at this point? please say
> it isn't so!

It isn't so.

irb(main):001:0> my_hash = {}
=> {}
irb(main):002:0> my_hash[ :key ] = { :price => 1.99, :quantity => 5 }
=> {:price=>1.99, :quantity=>5}
irb(main):003:0> puts my_hash[ :key ][ :price ]
1.99
=> nil
irb(main):004:0> my_hash[ :key ].each{ |key,value| puts "The #{key} is
#{value}" }
The price is 1.99
The quantity is 5
=> {:price=>1.99, :quantity=>5}