String#dump and interpolation

H

Hal Fulton

I'm working on a tiny code generation problem.

I like #dump because it puts things in readable form:
"\002\004\n" and so on.

I'm generating Ruby code from Ruby. I'm inserting some vars
and expressions in the strings:

name = "foo"
str = 'My value is #{' + name + '}' # Note the single quotes

However, when I do a dump of this, it marks the interpolated value
with a backslash (as a favor to me):

"My value is \#{foo}"

I want all of the other features of #dump, without the backslash
in front of interpolated values. How can I get that?

For now I'm just changing '\#{' to '#{' -- but what if my string
contains a real '\#{' someday (always a possibility in code
generation and metaprogramming)?


Thanks,
Hal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top