General question about function parameters and spaces

Why does Ruby frown upon putting spaces between a function name and the
left
parenthesis of its argument lists? Why does it matter? Is there some
other
language construct that uses a similar syntax that confuses Ruby so
much?

I just ran into an error with code like this:

print ( somefunc ( 1 ) + “abc” )

But rewriting it as below fixed the error:

print ( somefunc( 1 ) + “abc” )

Mike S.

Mike S. wrote:

Why does Ruby frown upon putting spaces between a function name and the
left parenthesis of its argument lists?

Because parentheses are optional around function parameters and can also
be
used for precedence. Ruby uses the space before the parenthesis to tell
whether they are used for the former or the latter. Example:

fun 1+35 == fun(1+35)
fun (1+3)*5 == fun((1+3)*5) != fun(1+3) * 5

HTH

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs