From: subbu Date: 2008-07-09T20:46:08+09:00 Subject: Re: 'ab\c' and 'ab\\c' Interesting findings. Thanks all for the explanations. On Jul 9, 2:25 pm, Calamitas wrote: > On Wed, Jul 9, 2008 at 11:00 AM, Max Williams > > wrote: > > I think you stumbled on another special character, \c, which seems to > > have some weird properties: > > > -in single quotes, must be followed by another character, but when it > > is, just swaps the \ for a \\ > > > -in double quotes, again must be followed by another character, which it > > translates into a number, though by what scheme i have no idea: > > In a double-quoted string, \c followed by another character forms a > control character. Control characters are character codes 0 to 31 in > the ASCII character set. When you call inspect on a string (as irb > does for you), Ruby escapes these control characters and those are the > number you are seeing. > > In a single-quoted string, \c doesn't do anything, just like "The Ruby > programming language" says. Irb gets confused here and does interpret > the \c, thinks the string goes on while it doesn't, asks more input > until a quote is given, which really starts a new string which is then > unterminated and that's the error you get. > > It's a bug in irb. > > Peter