From: Julian Leviston Date: 2008-04-01T13:25:16+09:00 Subject: Re: assignment if key_exist? in Hash What he's saying is if you want to retain the value of "false" or "nil", that won't work too well Learn about Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO OUT 3rd MARCH http://sensei.zenunit.com/ On 01/04/2008, at 3:15 PM, darren kirby wrote: > quoth the ara.t.howard: >> On Mar 31, 2008, at 9:30 PM, Peņa, Botp wrote: >>> foo = some_hash["some_key"] || foo >> >> that replaces even if the key is set to 'false', 'nil', or if the >> hash >> does not have the key... > > I don't understand...If the hash key doesn't exist then foo retains > its > original value. That is the behaviour I require: > >> foo = "Some String" >> h = {} >> foo = h["none_such"] || foo > => "Some String" >> h = {"some_key"=>"some value"} >> foo = h["some_key"] || foo > => "some value" > > -d > -- > darren kirby :: Part of the problem since 1976 :: http://badcomputer.org > "...the number of UNIX installations has grown to 10, with more > expected..." > - Dennis Ritchie and Ken Thompson, June 1972 >