From: Michael Campbell Date: 2003-08-30T04:15:42+09:00 Subject: Re: Bug? (1.8.0) --- Hal Fulton wrote: > Erik Veenstra wrote: > > Ruby 1.8.0 on win32: > > > > 1: ruby -e 'p "#abc#def#".gsub(/#$/, " ")' > > -e:1: unterminated string meets end of file > > -e:1: syntax error > > > > 2: ruby -e 'p "#abc#def#".gsub(/#/, " ")' > > " abc def " > > > > 3: ruby -e 'p "#abc#def#".gsub(/\#$/, " ")' > > "#abc#def " > > > > What's wrong with the first one? I expected the first one to > > behave like the third one. > > That's interesting and syntactically subtle. > > Here are the facts the explain this: > 1. Regexes can have interpolated values just like strings > 2. When an expression is a single name and that name starts > with a special symbol like @, @@, or $, the braces can > be omitted > 3. $/ is one of the ugly special variables > 4. So #$/ is interpreted as inserting the value of $/ into > the regex > 5. The regex then consumes the rest of the line > 6. The interpreter apparently does not distinguish between > strings and regular expressions when reporting that > something is unterminated. > > If there is a bug at all, it is #6 (misleading error message). Wow, I'd've never gotten that one, and I'm usually pretty good at catching stuff like that. I don't think I'd call it a bug, but to my eyes, #2 seems like a design "whodathunkit". Mind you, I'm really quite against poetry mode and a lot of other seemingly "magic" things the interpreter does (if I want interpolation in a string, I'll tell it so, in this case). __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com