Oh wait, I missed the part about needing an anonymous block. Hmm...
On Mon, Jan 31, 2011 at 7:41 PM, Jordan Fowler <[email protected]> wrote:
> You can also use a lambda:
>
> ruby-1.9.2-p136 :004 > [:collect, lambda { |x| x.to_s + "!" }]
> => [:collect, #<Proc:0x000001009a29b8@(irb):4 (lambda)>]
>
> On Mon, Jan 31, 2011 at 7:34 PM, Kevin Clark <[email protected]>wrote:
>
>> > Ben,
>> >
>> > So that works when it's being passed directly to send but it won't
>> > work when passed in from a splatted array!
>> >
>> > [1,2,3].send(*[:collect, &Proc.new{|x| x.to_s + "!"}])
>> > -> SyntaxError: (irb):1: expecting ']'
>>
>> That doesn't work because you can't put a block in an array:
>>
>> >> [:collect, &Proc.new{|x| x.to_s + '!'}]
>> SyntaxError: compile error
>>
>> Instead of storing the call and args in an array, you might want to
>> consider a hash so you can label and handle blocks special case.
>> There's some ambiguity in just shoving it in at the end of the args
>> (is it a user argument or a handler?).
>>
>> --
>> Kevin Clark
>> http://glu.ttono.us
>>
>> --
>> SD Ruby mailing list
>> [email protected]
>> http://groups.google.com/group/sdruby
>>
>
>
>
> --
> Jordan A. Fowler
> E-mail: [email protected]
> Website: http://www.jordanfowler.com
> Phone: (619) 339-6752
>
>
--
Jordan A. Fowler
E-mail: [email protected]
Website: http://www.jordanfowler.com
Phone: (619) 339-6752
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby