From: Chris Browne Date: 2007-05-04T03:13:18+09:00 Subject: Re: Array to Hash --Apple-Mail-11-192811929 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Good call, had value == nil in there but changed it right before I replied. -Chris- Automation Engineer Rally Software Development ph: 303-565-2857 www.rallydev.com On May 3, 2007, at 11:45 AM, james.d.masters@gmail.com wrote: > On May 3, 10:17 am, s...@seebs.net (Peter Seebach) wrote: >> In message , >> Chris Browne writes: >> >>> 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 >> >> My code was very similar to this. >> >> 5 quatloos to the first person to find a hypothetical case where >> this code >> produces the wrong answer. > > When values are false. Replace condition from "! value" to > "value.nil?". > > --Apple-Mail-11-192811929--