Forum: Ruby on Rails string interpolation - #{} vs. single vs. double quotes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-03-31 17:58
(Received via mailing list)
Could someone point me to documentation that provides a succinct and
accurate description of the difference between interpolation using #{},
single quotes, and double quotes ?

I imagine there's a set of precedence rules that govern behavior if/when
they're mixed.  I'd like to get clear on this.

Thanks,
Bill
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-31 18:13
(Received via mailing list)
In short:

Double quotes and heredoc evaluate #{}
SIngle quotes do not evaluate

http://www.rubycentral.com/book/tut_stdtypes.html#S2

Regards,

Łukasz
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-03-31 18:16
(Received via mailing list)
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-03-31 18:50
(Received via mailing list)
Thank you, Chris.  That's exactly what I was looking for.

The lack of an index on the Ruby PDF drives me nuts.  How do you find
this stuff?

Best regards,
Bill
  ----- Original Message -----
  From: Chris Hall
  To: rails@lists.rubyonrails.org
  Sent: 2006-03-31 10:10 AM
  Subject: Re: [Rails] string interpolation - #{} vs. single vs. double
quotes


  http://www.rubycentral.com/book/tut_stdtypes.html
  http://www.rubycentral.com/book/language.html

  would be a good place to start.


  On 3/31/06, Bill Walton <bill.walton@charter.net> wrote:
    Could someone point me to documentation that provides a succinct and
accurate description of the difference between interpolation using #{},
single quotes, and double quotes ?

    I imagine there's a set of precedence rules that govern behavior
if/when they're mixed.  I'd like to get clear on this.

    Thanks,
    Bill

    _______________________________________________
    Rails mailing list
    Rails@lists.rubyonrails.org
    http://lists.rubyonrails.org/mailman/listinfo/rails







------------------------------------------------------------------------------


  _______________________________________________
  Rails mailing list
  Rails@lists.rubyonrails.org
  http://lists.rubyonrails.org/mailman/listinfo/rails
2b891e820c238ded365d035771603f21?d=identicon&s=25 Bill Walton (Guest)
on 2006-03-31 18:59
(Received via mailing list)
Thanks, Lukasz.  I appreciate the help.  I was hoping there was a short
answer.  In reading the doc (now that you and Chris have helped me find
it)
it seems that I may need to explain (I'm working on a tutorial) the diff
between 'evaluate' and 'substitute' since single quotes do do some
substitution.  Or maybe I'll just say something like "In case A, use x.
In
case B, use y.  In case C, buy the book."  ;-)

Thanks again,
Bill

----- Original Message -----
From: "Łukasz Piestrzeniewicz" <bragi.ragnarson@gmail.com>
To: <rails@lists.rubyonrails.org>
Sent: 2006-03-31 10:09 AM
Subject: Re: [Rails] string interpolation - #{} vs. single vs. double
quotes


>
> >
> --
> Łukasz Piestrzeniewicz
> http://ragnarson.blogspot.com
>


----------------------------------------------------------------------------
----
Eea7ad39737b0dbf3de38874e0a6c7d8?d=identicon&s=25 Justin Forder (Guest)
on 2006-03-31 22:03
(Received via mailing list)
Łukasz Piestrzeniewicz wrote:

> Double quotes and heredoc evaluate #{}

Here documents can follow single-quote rules, if you single-quote the
here string (if that's what it's called) at the start:

question = <<'ENDQ'
Could someone point me to documentation that provides a
succinct and accurate description of the difference between
interpolation using #{}, single quotes, and double quotes ?
ENDQ

Try this in IRB, and you'll get:
=> "Could someone point me to documentation that provides a\nsuccinct
and accurate description of the difference between interpolation using
\#{}, single quotes, and double quotes ?\n"

regards

   Justin
00973881979aa0a660ffbbb2f7a907fb?d=identicon&s=25 Peter De Berdt (Guest)
on 2006-04-01 18:40
(Received via mailing list)
On 31 Mar 2006, at 18:32, Bill Walton wrote:

> Thank you, Chris.  That's exactly what I was looking for.
>
> The lack of an index on the Ruby PDF drives me nuts.  How do you
> find this stuff?
>

I'd recommend the Ruby for Rails book, all things make so much sense
afterwards. The agile web development book is great, but you never
learn the underpinnings of Rails.


Best regards

Peter De Berdt
This topic is locked and can not be replied to.