james.d.masters
5/3/2007 5:42:00 PM
On May 3, 10:17 am, s...@seebs.net (Peter Seebach) wrote:
> In message <D5AF5C55-270A-4E23-899D-11EAE7ED1...@rallydev.com>, 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?".