From: Jean-Hugues ROBERT Date: 2002-05-28T03:10:01+09:00 Subject: Re: Un-/Re-quoting strings At 02:37 28/05/2002 +0900, you wrote: >Hi, > >Is there a way to take a single-quoted string and direct the vm to >interpret it as a double-quoted string later? > >I want to have a debug_print that does not incur the expense of >interpolation unless $DEBUG (or some other flag) is set. > >It would look something like: > >if $DEBUG > def debug_print(str) > print str_nt str.requote > end > else > def debug_print(str) > end >end > >I guess I can do it with eval("\"" + str + "\""), but that seems >hackish to me. :-) > >Thanks! > >-a. You may have the interpolation occurring in a block that is evaluated only in debug mode: def debug_print( &a_block ) if $DEBUG print a_block.call() end end Then use: debug_print{"Hello"} instead of debug_print("Hello") . Yours, Jean-Hugues ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17