Ruby 1.8 preview1 questions

Hello

I have just installed Ruby 1.8.0 and find some changes to the syntax,
which I find confusing. These are:

irb(main):018:0> string = “asdfasdf”
=> "asdfasdf"
irb(main):019:0> string.method(“to_i”).call
=> 0
irb(main):020:0> string.method (“to_i”).call
NoMethodError: undefined method `call’ for “to_i”:String
from (irb):20

···

from :0

So basically if I type a space before opening parenthese I get an error.
I don’t think spacing should influence semantics (at least in this
place)

irb(main):027:0> class Klass
irb(main):028:1> def append ()
irb(main):029:2> return "jfdasdfj"
irb(main):030:2> end
irb(main):031:1> def do_something ()
irb(main):032:2> string = "asdfasdf"
irb(main):033:2> string << append ()
irb(main):034:2> end
irb(main):035:1> end
SyntaxError: compile error
(irb):33: parse error
string << append ()
^
from (irb):35
from :0

irb(main):036:0> class Klass
irb(main):037:1> def append ()
irb(main):038:2> return "jfdasdfj"
irb(main):039:2> end
irb(main):040:1> def do_something ()
irb(main):041:2> string = "asdfasdf"
irb(main):042:2> string << append
irb(main):043:2> end
irb(main):044:1> end
=> nil

So if I append () to the method call I got an error. I usually append ()
when calling method with no parameters to distinguish it from local
variables.

My question is: what was the reason to make such changes?


Marek Janukowicz

Hi,

So basically if I type a space before opening parenthese I get an error.
I don’t think spacing should influence semantics (at least in this
place)

Don’t put spaces before method argument parentheses, otherwise it’s
hard to distinguish from expression parentheses, i.e.

foo (a) → foo(a) or foo((a))? – no difference anyway
foo (a),b → foo(a),b or foo((a),b)?
p (a+b).abs → (p(a+b)).abs or p((a+b).abs)?

My question is: what was the reason to make such changes?

Because Ruby allows method arguments without surrounding parentheses,
spaces before open parenthesis are just ambiguous.

						matz.
···

In message “Ruby 1.8 preview1 questions” on 03/02/16, Child child@t9.ds.pwr.wroc.pl writes: