From: Renald Buter Date: 2001-05-11T20:42:00+09:00 Subject: [ruby-talk:14991] Re: Array -> Hash convertion? On Fri, May 11, 2001 at 01:10:00PM +0100, ruby-talk@ruby-lang.org wrote: > On Fri, 11 May 2001, Tammo Freese wrote: > > > At 19:23 11.05.01 +0900, Renald Buter wrote: > > >Sorry to raise another newbie question, > > > > > >Coming from a perl world, I like to write something like > > > > > > %hash = qw( foo led bar tender ) > > > > > >and have a hash initialized to > > > > > > {foo => led, bar => tender} > > > > > >Is anything like this possible in Ruby? > > > > hash = Hash[foo, led, bar, tender] > > That's if foo etc. are variables. In the Perl example they're > strings. So you'd have to do: > > hash = Hash[*%w{ foo led bar tender }] > > or equivalent. > > There's been a lot of array-to-hash-to-array discussion here. A > search for "to_h" at > will turn up > a bunch. > > > David I see. Well, I kinda expected something like your RCR in [ruby-talk:11195] to exist. But that's left to 1.8?? But your suggestion (and the others alike, BTW) will do the trick for me! Thanks all, Renald