From: Gavin Kistner Date: 2007-07-18T14:22:01+09:00 Subject: Re: syntactic sugar buzz Jeff Pritchard wrote: > One thing I keep running into over and over and over and over that I > wish there was some syntactic sugar for is the whole business of calling > a method on an object, and doing something intelligent if the object is > nil. > > If I have a string of stuff like: > blah = foo.bar.split > > what if bar is nil? Well, yes. What if bar is nil? Do you want blah to be nil? An empty array? I personally go with: blah = foo.bar.split unless foo.bar.nil? But really, I think the answer to your question (how do I do what I want) is the answer to your question (what do I want to do under this case). It seems that there is no good general answer for "perform the rough equivalent of method XYZ on nil and give me a reasonable result". -- Posted via http://www.ruby-forum.com/.