Daniel Lucraft wrote:
>> On Jul 17, 6:52 pm, Jeff Pritchard <j... / jeffpritchard.com> wrote:
>>> This could be written:
>>> blah = (foo.bar||"").split
> 
> Sometimes I think the brackets spoil how the expression reads. You could 
> define a method that looks like this:
> 
> blah = foo.bar.or("").split
> 
> Trainwreck though...
> 
> Dan

Thanks everyone.  This has at least convinced me that I wasn't missing 
some well known way to do this.

My choice of split confused the issue.  I should have used something 
unknown like "fred".

I was looking for a solution which, like the || operator, works with all 
object types, not just a string object, so that it could be used as a 
general rather than a specific solution.

In other words, the (something || "") solution works for split, because 
there is a convenient syntax for "empty string".

I was hoping for a more general (something || 
whateverneedstobeheretomakewhatfollowsworkright).fred

As another poster mentioned or hinted at, since "something" may not have 
a type yet, there's no way to get the needed object type from that.  I 
was hoping for something that can't be done without mind reading 
interpreters.

Ruby rocks, but it still lacks a generalized "you know what I mean" 
operator.  :)

jp

-- 
Posted via http://www.ruby-forum.com/.