R
Rolf Timmermans
Hi all,
Today I came across a very strange scenario that raises a syntax error =
in pretty much all Ruby implementations. I have absolutely no =
explanation for the following behaviour:
x :y
#=3D> bar.rb:1:in `<main>': undefined method `x' for main:Object =
(NoMethodError)
x =3D nil
x "y"
#=3D> bar.rb:2:in `<main>': undefined method `x' for main:Object =
(NoMethodError)
x =3D nil
x :y
#=3D> bar.rb:2: syntax error, unexpected ':', expecting $end
Why does that latter case raise a syntax error during parsing? Why would =
this be invalid Ruby? Why is it only invalid when supplying a symbol =
argument, and why only when the local variable with the same name is =
already defined? I would expect all three examples above to be run and =
abort with a NoMethodError.
The behaviour is consistent in Rubinius, JRuby, Ruby 1.9 and Ruby 1.8. =
What's going on, does anyone know?
Kind regareds,
Rolf Timmermans
Today I came across a very strange scenario that raises a syntax error =
in pretty much all Ruby implementations. I have absolutely no =
explanation for the following behaviour:
x :y
#=3D> bar.rb:1:in `<main>': undefined method `x' for main:Object =
(NoMethodError)
x =3D nil
x "y"
#=3D> bar.rb:2:in `<main>': undefined method `x' for main:Object =
(NoMethodError)
x =3D nil
x :y
#=3D> bar.rb:2: syntax error, unexpected ':', expecting $end
Why does that latter case raise a syntax error during parsing? Why would =
this be invalid Ruby? Why is it only invalid when supplying a symbol =
argument, and why only when the local variable with the same name is =
already defined? I would expect all three examples above to be run and =
abort with a NoMethodError.
The behaviour is consistent in Rubinius, JRuby, Ruby 1.9 and Ruby 1.8. =
What's going on, does anyone know?
Kind regareds,
Rolf Timmermans