From: Chris Browne Date: 2007-05-04T02:09:27+09:00 Subject: Re: Array to Hash --Apple-Mail-7-188256861 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed array = [ nil, "b", nil, nil, nil , "f", "g", nil, nil, "j"] hash = {} array.each_with_index { |value, index| hash[index] = value unless ! value } puts hash.inspect {5=>"f", 6=>"g", 1=>"b", 9=>"j"} -Chris- Automation Engineer Rally Software Development ph: 303-565-2857 www.rallydev.com On May 3, 2007, at 10:45 AM, Josselin wrote: > is it possible to convert easily an Array like this one : > > [ nil, "b", nil, nil, nil , "f", "g", nil, nil, "j"] > > to an Hash like this one > > { 1 => "b", 5 => "f", 6 => "g", 9 => "j" } > > where the key is the position of a value if not nil .. ? > > --Apple-Mail-7-188256861--