From: KOTP Date: 2010-10-12T11:31:50+09:00 Subject: Re: more idiomatic way to avoid errors when calling method on variable that may be nil? On Oct 11, 3:02 pm, Charles Calvert wrote: > I'm using Ruby 1.8.7 patchlevel 249 > > Is there a more idiomatic way to do the following? > > var = hash[key].nil? ? nil : hash[key].downcase This is identical to saying this: var = hash[key] && hash[key].to_s.downcase :: Hope that helps.