From: Benoit Daloze Date: 2010-04-18T23:10:26+09:00 Subject: [ruby-core:29598] Re: [Bug #3163] SyntaxError when using variable which is also a method in current scope with a Symbol argument --0016e659fb44ba6e34048483672a Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable >as in a ? b : c. Oups, I always forget that one. But to my defense it's only an operator if preceded by ? On 18 April 2010 07:44, Kornelius Kalnbach wrote: > On 17.04.10 20:26, Benoit Daloze wrote: > > I ran a few times in this bug, while using some "p :done"(and having > > a local var p) to trace the program execution quickly. > Translated into a Ruby style guide haiku: > > Never use p > As a local variable; > It breaks. > > [murphy] > > Sure, but that's why I showed that any variable which is also a method in a scope can cause this problem. That's right, I should really not use p, it's just because that's what happened to me most of the time. class Foo def bar(*args) :bar end def main bar =3D 2 # ... bar my: "hash" end end Foo.new.main I myself agree it's often not a good idea to name a variable with the name of a method you will use there without () and with an argument like a literal Symbol/Hash. And the names of the methods usually are not appropriate for the name of a variable. But, it's not because this shouldn't appear too much it shouldn't be fixed. Also in this case, the error is very disturbing: > p =3D 0; p %Q{a} NoMethodError: undefined method `Q' for main:Object Let's take your examples: p =3D 0 p %[foo] p /foo/x p &foo p *foo p ?f : g p <>as in a ? b : c.
Oups, I always forget th= at one. But to my defense it's only an operator if preceded by ?
On 18 April 2010 07:44, Kornelius Kalnbach <murphy@rubychan.de>= wrote:
On 17.04.10 = 20:26, Benoit Daloze wrote:
> I ran a few times in this bug, while using some "p :done"(an= d having
> a local var p) to trace the program execution quickly.
Translated into a Ruby style guide haiku:

=A0Never use p
=A0As a local variable;
=A0It breaks.

[murphy]

=A0
Sure, but that's why I showed that= any variable which is also a method in a scope can cause this problem.
= That's right, I should really not use p, it's just because that'= ;s what happened to me most of the time.

class Foo
=A0 def bar(*args)
=A0=A0=A0 :bar
=A0 end
=A0 =A0 def main
=A0=A0=A0 bar =3D 2
=A0=A0=A0 # ...
=A0=A0=A0 bar my= : "hash"
=A0 end
end
Foo.new.main

I myself agree = it's often not a good idea to name a variable with the name of a method= you will use there without () and with an argument like a literal Symbol/H= ash. And the names of the methods usually are not appropriate for the name = of a variable.

But, it's not because this shouldn't appear too much it shouldn= 't be fixed.

Also in this case, the error is very disturbing:> p =3D 0; p %Q{a}
NoMethodError: undefined method `Q' for main:= Object

Let's take your examples:
p =3D 0
p %[foo]
p /foo/x
p &= amp;foo
p *foo
p ?f : g
p <<foo

They are all raising = "NameError: undefined local variable or method =91foo=92 for main:Obje= ct" except the one with the ternary condition.

I think in all these cases, it should be considered as an operator only= if there is a space after, because you use a space before.
If there is = no space, then it should be an operator.
If there is more spaces at left= than right of the 'operator' it should be a method.
p % [a] # operator
p %[a] # method
p%[a] # operator

This idea = is valid only if the right part is a literal expression:
p % a , p %a , = p%a are in all cases operators.

Would it be possible to implement a = rule like that:
"if more spaces at left than right and right is a literal expression, = consider left as a method" (instead of always as an operator)

A= re you thinking the same way to consider theses expressions ?

This c= hange is only an improvement to my opinion, so I don't see when it can = cause problems.

And the most important, thank you, Nobu, for resolving the main issue o= f this bug :)
--0016e659fb44ba6e34048483672a--