parentheses and newlines


J

jsnark

Can anyone explain the following behavior? I would expect both
expressions to fail, but the first unexpectedly succeeds.

$ irb --version
irb 0.9.6(09/06/30)
$ ruby --version
ruby 1.9.2p136 (2010-12-25) [x86_64-linux]
$ irb
irb(main):001:0> (2
irb(main):002:1> 3)
=> 3
irb(main):003:0> (2 3)
SyntaxError: (irb):3: syntax error, unexpected tINTEGER, expecting ')'
(2 3)
^
from /usr/local/ruby-1.9.2/bin/irb:12:in `<main>'
 
Ad

Advertisements

R

Robert Klemme

Can anyone explain the following behavior? I would expect both
expressions to fail, but the first unexpectedly succeeds.

$ irb --version
irb 0.9.6(09/06/30)
$ ruby --version
ruby 1.9.2p136 (2010-12-25) [x86_64-linux]
$ irb
irb(main):001:0> (2
irb(main):002:1> 3)
=> 3
irb(main):003:0> (2 3)
SyntaxError: (irb):3: syntax error, unexpected tINTEGER, expecting ')'
(2 3)
^
from /usr/local/ruby-1.9.2/bin/irb:12:in `<main>'

irb(main):001:0> (2;3)
=> 3

Line terminator is more than just whitespace.

Kind regards

robert
 
Ad

Advertisements

S

Simon Krahnke

* jsnark said:
Can anyone explain the following behavior? I would expect both
expressions to fail, but the first unexpectedly succeeds.

$ irb --version
irb 0.9.6(09/06/30)
$ ruby --version
ruby 1.9.2p136 (2010-12-25) [x86_64-linux]
$ irb
irb(main):001:0> (2
irb(main):002:1> 3)
=> 3
irb(main):003:0> (2 3)
SyntaxError: (irb):3: syntax error, unexpected tINTEGER, expecting ')'
(2 3)
^
from /usr/local/ruby-1.9.2/bin/irb:12:in `<main>'

Same behaviour in ruby with eval. So no irb problem.

mfg, simon .... l
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top