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.
Bill W. (Guest)
on 2006-03-31 19: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
Łukasz Piestrzeniewicz (Guest)
on 2006-03-31 20: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
Chris H. (Guest)
on 2006-03-31 20:16
(Received via mailing list)
Bill W. (Guest)
on 2006-03-31 20: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 H.
  To: removed_email_address@domain.invalid
  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 W. <removed_email_address@domain.invalid> 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
    removed_email_address@domain.invalid
    http://lists.rubyonrails.org/mailman/listinfo/rails







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


  _______________________________________________
  Rails mailing list
  removed_email_address@domain.invalid
  http://lists.rubyonrails.org/mailman/listinfo/rails
Bill W. (Guest)
on 2006-03-31 20: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" <removed_email_address@domain.invalid>
To: <removed_email_address@domain.invalid>
Sent: 2006-03-31 10:09 AM
Subject: Re: [Rails] string interpolation - #{} vs. single vs. double
quotes


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


----------------------------------------------------------------------------
----
Justin F. (Guest)
on 2006-04-01 00: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
Peter De Berdt (Guest)
on 2006-04-01 20:40
(Received via mailing list)
On 31 Mar 2006, at 18:32, Bill W. 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.