On Mon, Jan 31, 2011 at 9:11 PM, Xavier Lange <[email protected]> wrote:
> As my knowledge of Object#send stands now: it can't recreate the full
> breadth of method invocations in ruby. Object#send should accept an
> optional parameter:
>
> [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!
Not quite. Send can pass the block just fine. But the way you're
storing your information doesn't allow you (as the person calling
send) to split it out.
=> {:method=>:collect, :block=>#<Proc:0x00000001012ee558@(irb):2>}
>> [1,2,3].send(data[:method], &data[:block])
=> ["1!", "2!", "3!"]
I was saying the way you're storing what essentially amount to bound
method calls is ambiguous:
REVIEW_EXTRACTION =
{
:most_common_node => [[:css, "a + br + div > div + div >
span > span > span"], [:collect, &Proc.new{|x|
x.parent_node.parent_node.parent_node.parent_node.parent_node}]],
[:collect, &...] could only express method(arg1, arg2, arg3, &myblock)
if you strip off the first and last item, and set args equal to the
rest. You couldn't just splat everything after collect and expect it
to work (since blocks aren't really a positional argument).
Does that makes sense? You don't need to extend the class, you just
need to tweak your data.
--
Kevin Clark
http://glu.ttono.us
--
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby