Syntax sugar: treating an object like a method

>> Another note: as far as I remember there are plans to make
()
>> work for
>> lambdas. So currently we have
>>
>>>> f = lambda {|x| x+x}
>> => #<Proc:0x100c3e60@(irb):15>
>>>> f[10]
>> => 20
>>>> f.call 10
>> => 20
>>
>> Then we had additionally
>>
>>>> f(10)
>> => 20
>
> Cool. So, this sounds like the ()/null operator is being
> implemented with procs/lambdas. Now if we could just have
it
> for the rest of the objects.

It'll probably work as general mapping to #call so it would
work with
everything that has #call.

Cheers

    robert

Thanks Robert. If that is the case, it sounds like I'll get
the main thing I wanted - ()/null operator.

Anybody know if lambdas will also support blocks anytime soon?
It doesn't seem to make sense why I can't do this:

f = lambda {|*args,&block|puts(*args);block}
f[1,2,3] { puts("hi") }

or in the 1.9 syntax:

f = {|*args,&block|puts(*args);block}
f(1,2,3) { puts("hi") }

I just grabbed 1.9 and none of this new syntax seems to work.

Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html

Eric Mahurin <eric_mahurin@yahoo.com> writes:

Anybody know if lambdas will also support blocks anytime soon?
It doesn't seem to make sense why I can't do this:

f = lambda {|*args,&block|puts(*args);block}
f[1,2,3] { puts("hi") }

or in the 1.9 syntax:

f = {|*args,&block|puts(*args);block}
f(1,2,3) { puts("hi") }

I just grabbed 1.9 and none of this new syntax seems to work.

Blocks should be able to take blocks since 1.9. I tried that not too
long ago.

ยทยทยท

--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org