From: Hal Fulton Date: 2003-08-30T03:46:06+09:00 Subject: Re: Bug? (1.8.0) 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). Hal