[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: #{} and \" don't like each other

Mark Wilson

9/17/2003 12:09:00 AM

To combine two of my e-mails into one:

1. double-quote as beginning of string literal,
2. string interpolation open,
3. double-quote as beginning of string literal,
4. double-quote as character,

Trying to do 4. by escaping the double-quote renders the double quote
an end of string literal marker.

The following does not work as intended (the expression is evaluated
differently than it would be in a variable assignment):

print "<user #{"name=\"" + name + \""}></user>"

The effect in 4. can be done by enclosing the string literal inside the
string interpolation in single-quotes.

alternate 3. single-quote as beginning of string literal,
alternate 4. double-quote as character

The following does work as intended:

print "<user #{'name="' + name + '"'}></user>"

5. double-quote as end of string literal,
alternate 5. single-quote as end of string literal,
6. string interpolation close, and
7. double-quote as end of string literal

As to why, I don't know. As to whether it is necessary that it be this
way, I don't know.

Regards,

Mark