From: Tony Arcieri Date: 2010-10-13T14:45:41+09:00 Subject: Re: more idiomatic way to avoid errors when calling method on variable that may be nil? --0016363b9e5a68f6190492791aae Content-Type: text/plain; charset=ISO-8859-1 On Tue, Oct 12, 2010 at 6:39 AM, Rick DeNatale wrote: > Nobody seems to have mentioned it, I guess since this is the place for > 'pure' rubyists, but Rails has the following methods: > > So with this you can write simply > > var = hash[key].try(:downcase) > That's pretty cool, but I'd prefer it return a proxy object for all non-nil objects that just relays the method call, and for nil a proxy that always returns nil, ala: hash[key].try.downcase -- Tony Arcieri Medioh! A Kudelski Brand --0016363b9e5a68f6190492791aae--