From: Jacob Fugal Date: 2005-05-19T06:47:37+09:00 Subject: Re: (newbie Q) opposite of inspect for strings On 5/18/05, Basile Starynkevitch [news] wrote: > Sorry for having expressed myself poorly. I mean > > a="a\tb" > > binds variable a to a 3 character string (a, tab, b) > > aa=a.inspect > > binds variable aa to a 6 character string (dblquote, a, backslash, t, > b, dblquote) > > I'm desperately seeking a function f such that > > b = f(aa) > > binds variable b to a 3 character string which is equal to the value > of a, or I am seeking a method m such that > > c = aa.m > > binds variable c to a 3 character string (a, tab, b) equal to the > value of a. > > The to_s method is not a valuable substitute for m since aa.to_s is a > 6 character string (equal to aa) What you probably need is eval: irb(main):001:0> VERSION => "1.8.2" irb(main):002:0> a = "a\tb" => "a\tb" irb(main):003:0> aa = a.inspect => "\"a\\tb\"" irb(main):004:0> b = eval(aa) => "a\tb" irb(main):005:0> a == b => true Of course, you want to be careful when using eval, but it should cut it for the simple case... Jacob Fugal