From: Joel VanderWerf Date: 2006-10-29T14:35:02+09:00 Subject: Re: Define a hash using %q? Joe Ruby MUDCRAP-CE wrote: > Is there a way for us lazy typists to define a hash using %q? I tried > this, but it doesn't create a hash: > > h = %q(a => b, c => d) irb(main):006:0> Hash[*%w{ a b c d }] => {"a"=>"b", "c"=>"d"} More decadent: irb(main):008:0> def mkh arg; Hash[*arg]; end => nil irb(main):009:0> mkh %w{ a b c d } => {"a"=>"b", "c"=>"d"} Ultra decadent: irb(main):017:0> class Array; def -@; Hash[*self]; end; end => nil irb(main):018:0> -%w{ a b c d } => {"a"=>"b", "c"=>"d"} -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407