MonkeeSage
9/20/2006 3:40:00 AM
Note also that in the context of a hash literal (i.e., { ... }) or the
explicit constructor (i.e., Hash[ ... ]) you may use commas instead the
the 'fatarrow'.
h = {:a, 'hi,', :b, 'how are', :c, 'you?'}
# or ...
# h = Hash[:a, 'hi,', :b, 'how are', :c, 'you?']
h.keys.sort.each { |k| p "#{k} => #{h[k]}" }
This can't work for implied hashes in method calls (i.e., without the
braces) because there would be no (easy, reliable) way to tell the keys
and values of the hash from normal method parameters (which are also
seperated by commas). You can make it explicit (with the { ... }) and
use the commas there too however.
Regards,
Jordan