I'll give one more option:

ruby-1.9.2-p0 > [1,2,3].send(:collect) { |x| x * 2 }
 => [2, 4, 6]

Not sure if that suits your use case.

--Dan

On Mon, Jan 31, 2011 at 9:41 PM, Matt Aimonetti <[email protected]>wrote:

> Xavier,
>
>
>> [1,2,3].send(:collect, :block => lambda{|x| x.to_s+"!"})
>>
>> That obviously wouldn't work because it's still ambiguous. Oh well.
>> I'll just extend the nokogiri class! Thanks for playing everyone!
>>
>
>
> I didn't read the entire thread but that would work:
> [1,2,3].map &lambda{|x| x.to_s+"!"}
> => ["1!", "2!", "3!"]
>
> >> [1,2,3].send(:map, &lambda{|x| x.to_s+"!"})
> => ["1!", "2!", "3!"]
>
> Probably not what you're after tho.
>
>
> Mike...., you might want to contact Kevin directly and not via the ML ;)
> (and super scoop, no he doesn't work for Powerset/Microsoft anymore ;))
>
>
> - Matt
>
>
> On Mon, Jan 31, 2011 at 9:19 PM, Mike O'Brien <[email protected]> wrote:
>
>> Hey man, what are you up to these days???
>>
>> Are you still with powerset?  How's it working for the man?  Are you still
>> in san jose?
>>
>> Sent from my iPhone
>>
>> On Jan 31, 2011, at 7:49 PM, Kevin Clark <[email protected]> wrote:
>>
>> > Yeah, doesn't matter if you could curry it or not - it needs to be
>> > passed as a block. If you don't separate them, there's no way to
>> > detect it *should* be separated. *args can't work. That's why method
>> > missing takes them separate - blocks are considered their own part of
>> > the call, and you only get one.
>> >
>> > On Mon, Jan 31, 2011 at 7:43 PM, Jordan Fowler <[email protected]>
>> wrote:
>> >> 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
>> >
>> >
>> >
>> > --
>> > Kevin Clark
>> > http://glu.ttono.us
>> >
>> > --
>> > SD Ruby mailing list
>> > [email protected]
>> > http://groups.google.com/group/sdruby
>>
>> --
>> SD Ruby mailing list
>> [email protected]
>> http://groups.google.com/group/sdruby
>>
>
>  --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
>

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to