Excerpt from The Ruby P.ming Language book:
-----------------------------------------------------------------------------
When you use parentheses in a method invocation, the opening
parenthesis
must immediately follow
the method name, with no space.
This is because parentheses can be used around an argument list in
a
method invocation, and they can be used for grouping expressions.
Consider the following two examples:
square(2+2)*2 # square(4)*2 = 16*2 = 32
square (2+2)*2 # square(4*2) = square(8) = 64
In the first expression, the parentheses represent method invocation.
In the second, they represent expression grouping.
To reduce the potential for confusion, you should always use
parentheses around a method invocation if any of the arguments use
parentheses.
The second expression would be written more clearly as:
square((2+2)*2)
-----------------------------------------------------------------------------
In Ruby 1.8.x interpreter issued an warning, in Ruby 1.9.y they decided
to issue an error when interpreter encounters something like foo
(args).
-----
Eugen
On 08/02/2010 05:45 PM, VMDD TECH wrote:
Hello everyone,
I am new to Ruby.
If there are spaces between new and (, then ruby 1.9.1p376 considers
it a syntactical error. For example:
File.new (“write.txt”, “w+”)
=>
syntax error, unexpected ‘,’, expecting ‘)’
File.new (“write.txt”, “w+”)
^
…: syntax error, unexpected ‘)’, expecting $end
Is this a ruby bug or is it a feature/quirk of ruby?
By the way, if I write as
File.new “write.txt”, “w+”
File.new(“write2.txt”, “w+”)
then there are no problem.
Thanks,
Binh