Forum: Ruby failure to parse multiple (procs with do end blocks) as method arguments

Posted by Mean L. (mean_l)
on 2012-11-01 18:57
This fails:

foo proc do

end, proc do

end

this works:

foo(proc do

end, proc do

end)

that it doesn't work without parens suggests that there may be
ambiguity, but I don't think there is, the second proc can not be an arg
to the first since it follows the block of the first, also this works
without parens:

foo proc {

}, proc {

}

why is there a difference?

Is there a bug here?  If not, what's the reason?
Posted by Bartosz DziewoƄski (matmarex)
on 2012-11-01 19:57
(Received via mailing list)
2012/11/1 Mean L. <lists@ruby-forum.com>:
> foo proc do
>
> end, proc do
>
> end

foo proc do end is being interpreted as foo(proc) do end, so you get a
syntax error on the comma.

The curly { } block have higher priority when parsing, so foo proc { }
is interpreted as foo(proc { }) and the entire thing works.

-- Matma Rex
Posted by Mean L. (mean_l)
on 2012-11-03 21:18
thanks, good to know about different binding precedence of do end and {}
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.