From: Joel VanderWerf Date: 2010-10-14T09:13:56+09:00 Subject: Re: more idiomatic way to avoid errors when calling method on variable that may be nil? On 10/13/2010 04:26 PM, Tony Arcieri wrote: > On Mon, Oct 11, 2010 at 10:04 PM, Joel VanderWerf > wrote: > >> You can get around this by putting ( ) around the whole if clause: >> >> var = (hash[key].downcase if hash[key]) >> >> It works because (... if ...) returns nil if the condition is false. >> > > The parens are unnecessary. The "var" variable will be implicitly bound to > nil if the if condition isn't true. As David Black pointed out: var = 1 var = 2 if false p var # ==> 1