From: Rolf Timmermans Date: 2011-01-17T19:25:40+09:00 Subject: Obscure syntax error 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 #=> bar.rb:1:in `
': undefined method `x' for main:Object (NoMethodError) x = nil x "y" #=> bar.rb:2:in `
': undefined method `x' for main:Object (NoMethodError) x = nil x :y #=> 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