From: Joel VanderWerf Date: 2003-01-08T01:31:33+09:00 Subject: Re: Hash Syntax ts wrote: > "D" == Dominik Werder writes: > > > D> The key/value pairs are devided by a linefeed. Can we teach ruby to > D> understand it also without the comma? > > Well, if you want to write it > > h = { > 'key1' => 'value1' # no comma > 'key2' => 'value2' # no comma > 'key3' => 'value3' # no comma > } > > then no, ruby will give a parse error, > > D> I want to generate Hash definitions dynamically by another program and > D> to omit the commas would be very useful. > > but you can write it > > h = { > 'key1' => 'value1', # comma > 'key2' => 'value2', # comma > 'key3' => 'value3', # comma > } If your keys and values are always strings, you can do this: h = Hash[*%w{ key1 value1 key2 value2 key3 value3 }]