From: "Jesús Gabriel y Galán" Date: 2011-01-17T20:19:55+09:00 Subject: Re: Obscure syntax error On Mon, Jan 17, 2011 at 12:02 PM, Peter Hickman wrote: > The format > > x ...followed by something else... > > means that x is a method and anything that follows it is a parameter. > Since you don't have a method called x you get "undefined method `x'" > just like it says in the error message. > > When x is a reference to a variable by itself it just returns its > value, but when you put a parameter after it it looks for a method > called x, because you are passing it a parameter "y" and the only > things you pass parameters to are methods so you get the "undefined > method `x'" message again. > > In the final case again you have no method called x and therefore a > parameter, in this case the :y, is unexpected. In that you don't pass > parameters to a variable only to methods. > > It's good that you checked it out in all the various implementations > of Ruby but the error message was quite clear, "undefined method `x'" > means that Ruby thinks x should be a method but you don't have a > method x defined. What I don't understand is the difference between x "y" and x :y irb(main):001:0> x = nil => nil irb(main):002:0> x "y" NoMethodError: undefined method `x' for main:Object from (irb):2 from :0 irb(main):003:0> x :y SyntaxError: compile error (irb):3: syntax error, unexpected ':', expecting $end from (irb):3 from :0 Why the second case is not a NoMethodError too? Jesus.