On Jul 20, 7:18 am, Stefan Rusterholz <apei... / gmx.net> wrote:
> Robert Dober wrote:
> > On 7/20/07, Trans <transf... / gmail.com> wrote:
>
> > But -> does not support default, that is a feature of your solution.
> > I have completely overlooked this :(, the -> notation implies nil as
> > default.
>
> > And you are thus right about the example above, your idea is indeed
> > powerful :)
>
> > Robert
>
> Well, default can still be established with ->, just the plain old way:
> foo = bar->baz || default # if anywhere in the chain is nil, you get the
> default

Sure. I realize. I'm only pointing out that this -> operator is
equivalent to a rescue NoMethodError, so maybe we just need a way to
specify that better, rather then a whole new dispatcher which can
greatly hurt code readability, IMHO. So a keyword besides 'rescue'
might do the trick, maybe 'default' would be better? I just thru |||
out there b/c of it's similarity to ||. So...

  foo = bar.baz default nil

Another possibility... perhaps we can add a feature to #tap (which has
already been added to Ruby 1.9) so that:

  foo = bar.tap.baz

does the trick.

T.