# Bug? (1.8.0)

**URL:** <https://rubytalk.org/t/bug-1-8-0/7698>\
**Category:** ruby-talk\
**Created:** [29 August 2003 18:39 UTC](https://rubytalk.org/t/bug-1-8-0/7698 "2003-08-29T18:39:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik\_Veenstra3](https://avatars.discourse-cdn.com/v4/letter/e/f9ae1b/32.png) [@Erik\_Veenstra3](https://rubytalk.org/u/Erik_Veenstra3)\
**Post date:** [29 August 2003 18:39 UTC](https://rubytalk.org/t/bug-1-8-0/7698/1 "2003-08-29T18:39:07Z")

</div>

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.

gegroet,  
Erik V.

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [29 August 2003 18:46 UTC](https://rubytalk.org/t/bug-1-8-0/7698/2 "2003-08-29T18:46:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daniel\_Carrera](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Daniel\_Carrera](https://rubytalk.org/u/Daniel_Carrera)\
**Post date:** [29 August 2003 18:49 UTC](https://rubytalk.org/t/bug-1-8-0/7698/3 "2003-08-29T18:49:40Z")

</div>

> 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.

I’m not sure I followed that. Can you explain to me how 1-6 explain  
this?:

> > p “#$”  
> > SyntaxError: compile error  
> > (irb):22: unterminated string meets end of file  
> > from (irb):22

> **···**
>
> –  
> Daniel Carrera, Math PhD student at UMD. PGP KeyID: 9AF77A88  
> .-“~~~”-.  
> / O O \ ATTENTION ALL PASCAL USERS:  
> : s :  
> \ \_**/ / To commemorate the anniversary of Blaise Pascal’s  
> `-.**\_.-’ birth (today) all your programs will run at half speed.

---

<div class="post-metadata">

**Author:** ![Michael\_Campbell1](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@Michael\_Campbell1](https://rubytalk.org/u/Michael_Campbell1)\
**Post date:** [29 August 2003 19:15 UTC](https://rubytalk.org/t/bug-1-8-0/7698/4 "2003-08-29T19:15:42Z")

</div>

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).

> **···**
>
> — Hal Fulton [hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com) 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).
> 
> * * *
> 
> Do you Yahoo!?  
> Yahoo! SiteBuilder - Free, easy-to-use web site design software  
> [http://sitebuilder.yahoo.com](http://sitebuilder.yahoo.com)

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [29 August 2003 18:53 UTC](https://rubytalk.org/t/bug-1-8-0/7698/5 "2003-08-29T18:53:03Z")

</div>

Daniel Carrera wrote:

> > 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.
> 
> I’m not sure I followed that. Can you explain to me how 1-6 explain  
> this?:
> 
> > > p “#$”
> 
> SyntaxError: compile error  
> (irb):22: unterminated string meets end of file  
> from (irb):22

Isn’t $" also a special variable?

Hal

---

<div class="post-metadata">

**Author:** ![Daniel\_Carrera](https://avatars.discourse-cdn.com/v4/letter/d/c67d28/32.png) [@Daniel\_Carrera](https://rubytalk.org/u/Daniel_Carrera)\
**Post date:** [29 August 2003 18:56 UTC](https://rubytalk.org/t/bug-1-8-0/7698/6 "2003-08-29T18:56:50Z")

</div>

> > > > p “#$”
> > 
> > SyntaxError: compile error  
> > (irb):22: unterminated string meets end of file  
> > from (irb):22
> 
> Isn’t $" also a special variable?

Okay, I would suggest the following behaviour would make most sense:

p “#$” =\> ‘#$’  
p “#{$”}" =\> contents of $"

Thoughts?

> **···**
>
> –  
> Daniel Carrera, Math PhD student at UMD. PGP KeyID: 9AF77A88  
> .-“~~~”-.  
> / O O \ ATTENTION ALL PASCAL USERS:  
> : s :  
> \ \_**/ / To commemorate the anniversary of Blaise Pascal’s  
> `-.**\_.-’ birth (today) all your programs will run at half speed.

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [29 August 2003 19:10 UTC](https://rubytalk.org/t/bug-1-8-0/7698/7 "2003-08-29T19:10:45Z")

</div>

Daniel Carrera wrote:

> > > > > p “#$”
> > > 
> > > SyntaxError: compile error  
> > > (irb):22: unterminated string meets end of file  
> > > from (irb):22
> > 
> > Isn’t $" also a special variable?
> 
> Okay, I would suggest the following behaviour would make most sense:
> 
> p “#$” =\> ‘#$’  
> p “#{$”}" =\> contents of $"
> 
> Thoughts?

I’d rather just see the ugly variables go away.  
_The Ruby Way_ intentionally avoided their use. There are a few  
in there, but most are in code contributed by others.

Rather than change the parser, I’d suggest that the nuby should  
be aware that #$ will interpolate a global variable if the rest  
of the variable name is valid.

I’ve been playing in irb and this is making my head hurt.

Personally I’d say: If you want a literal #$, then either escape  
the $ or use a non-interpolating string.

Hal

---

<div class="post-metadata">

**Author:** ![Lyle\_Johnson4](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Lyle\_Johnson4](https://rubytalk.org/u/Lyle_Johnson4)\
**Post date:** [30 August 2003 14:22 UTC](https://rubytalk.org/t/bug-1-8-0/7698/8 "2003-08-30T14:22:21Z")

</div>

Rene van Bevern wrote:

> can “The Ruby Way” be found online, like the pickaxe?

Sure, here’s one link:

> **[The Ruby Way: Fulton, Hal Edwin: 9780672320835: Amazon.com: Books](https://www.amazon.com/Ruby-Way-Hal-Fulton/dp/0672320835)**
>
> The Ruby Way \[Fulton, Hal Edwin\] on Amazon.com. \*FREE\* shipping on qualifying offers. The Ruby Way

---

<div class="post-metadata">

**Author:** ![Laurent\_Julliard4](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@Laurent\_Julliard4](https://rubytalk.org/u/Laurent_Julliard4)\
**Post date:** [30 August 2003 23:44 UTC](https://rubytalk.org/t/bug-1-8-0/7698/9 "2003-08-30T23:44:04Z")

</div>

I think you may have a free subscription to [safari.oreilly.com](http://safari.oreilly.com) for 14  
days and get an electronic copy from there. You may need to pay after  
that time, anyway…

> **···**
>
> il Sat, 30 Aug 2003 11:53:58 +0200, Rene van Bevern [rvb@rvb.dyndns.org](mailto:rvb@rvb.dyndns.org) ha scritto::
> 
> > can “The Ruby Way” be found online, like the pickaxe? (although i have  
> > the pickaxe in “bookform”).

---

<div class="post-metadata">

**Author:** ![HAL\_9000](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@HAL\_9000](https://rubytalk.org/u/HAL_9000)\
**Post date:** [30 August 2003 17:27 UTC](https://rubytalk.org/t/bug-1-8-0/7698/10 "2003-08-30T17:27:14Z")

</div>

Lyle Johnson wrote:

> Rene van Bevern wrote:
> 
> > can “The Ruby Way” be found online, like the pickaxe?
> 
> Sure, here’s one link:
> 
> [http://www.amazon.com/exec/obidos/ASIN/0672320835/102-1067493-2732943](http://www.amazon.com/exec/obidos/ASIN/0672320835/102-1067493-2732943)

🙂 No, surely he means the full text.

_The Ruby Way_ is not open-sourced, so there’s no  
free electronic copy.

I’ve heard that [safari.net](http://safari.net) has it – downloadable  
for a fee of some kind.

Hal

---

<div class="post-metadata">

**Author:** ![Rene\_van\_Bevern](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@Rene\_van\_Bevern](https://rubytalk.org/u/Rene_van_Bevern)\
**Post date:** [30 August 2003 18:22 UTC](https://rubytalk.org/t/bug-1-8-0/7698/11 "2003-08-30T18:22:57Z")

</div>

> 🙂 No, surely he means the full text.

right 😉 … and i refuse to buy at amazon.

> I’ve heard that [safari.net](http://safari.net) has it – downloadable  
> for a fee of some kind.

downloading for a fee? … no thanks, then i will just buy your book on  
paper ;\> … i prefer paperbooks, although they are not grep-able  
i have just read the sample pages … looks good 😉

```
Rene

```

> **···**
>
> On Sun, 31 Aug 2003 02:27:14 +0900, Hal Fulton [hal9000@hypermetrics.com](mailto:hal9000@hypermetrics.com) wrote:
