String interpolation - #{} vs. single vs. double quotes

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

In short:

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

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

Regards,

Łukasz

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

would be a good place to start.

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: [email protected]
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. [email protected] 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
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Ł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

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.” :wink:

Thanks again,
Bill

----- Original Message -----
From: “Łukasz Piestrzeniewicz” [email protected]
To: [email protected]
Sent: 2006-03-31 10:09 AM
Subject: Re: [Rails] string interpolation - #{} vs. single vs. double
quotes


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



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