From: Francis Hwang Date: 2004-12-01T09:58:57+09:00 Subject: Re: singleton methods : when are they not permitted? On Nov 30, 2004, at 6:12 PM, Florian Gross wrote: > It also seems not to be possible to directly add methods to literals > like this: (Not sure why -- maybe Ruby optimizes literals?) > > irb(main):014:0> def ("x").foo; end > SyntaxError: compile error > (irb):14: can't define singleton method for literals > > However this can be worked around trivially by using an expression > instead: > > irb(main):015:0> def (("x")).foo; end > => nil Errrr. So what's the difference between def ("x").foo; end and def (("x")).foo; end Why do the extra parens make the parser treat it differently? My head hurts. Francis Hwang http://fhwang.net/