String#dump and interpolation

Discussion in 'Ruby' started by Hal Fulton, Jun 20, 2004.

  1. Hal Fulton

    Hal Fulton Guest

    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
     
    Hal Fulton, Jun 20, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aiden Humphreys

    Perl/Ruby string interpolation

    Aiden Humphreys, May 22, 2005, in forum: Java
    Replies:
    5
    Views:
    876
    Tor Iver Wilhelmsen
    May 22, 2005
  2. halfdog
    Replies:
    12
    Views:
    12,465
  3. Paul Rubin
    Replies:
    4
    Views:
    300
    Michele Simionato
    Jan 19, 2004
  4. Michele Simionato

    yet another recipe on string interpolation

    Michele Simionato, Nov 4, 2004, in forum: Python
    Replies:
    8
    Views:
    402
    Raymond Hettinger
    Nov 8, 2004
  5. Kun
    Replies:
    2
    Views:
    423
    John J. Lee
    Apr 12, 2006
Loading...

Share This Page