From: x1 Date: 2006-12-01T12:41:42+09:00 Subject: Re: time = ["min", "sec"].collect {|i| {i=> Time.now.send(i).to_i}} ok..nvrmind.. I think I got it: time = Hash[*["min", "sec"].collect { |i| [i, Time.now.send(i)]}.flatten] :-) On 11/30/06, x1 wrote: > Sorry --Subject was supposed to be "Need help creating hash from an array" > > On 11/30/06, x1 wrote: > > What's the best way to make the first item below yield a hash instead > > of an array in one line? I'm struggling :( > > > > #doesnt work > > time = ["min", "sec"].collect {|i| {i=> Time.now.send(i).to_i}} > > puts time.type # Array > > > > #works > > time = ["min", "sec"].collect {|i| {i=> Time.now.send(i).to_i}}.first > > puts time.type # Hash > > puts time['min'] > > > > Thanks in advance > > > > > >