On 2005-05-18, Jacob Fugal <lukfugl / gmail.com> wrote:
> On 5/18/05, Basile Starynkevitch [news] <basile-news / starynkevitch.net> wrote:
>> 
>> 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:

A big thanks for this suggestion!

>
>   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...

Is there some specialized version which does not evaluate its
(arbitrary) input, but just unformat a formatted string (and no more,
in particular refuse non-string lexemes such as arbitrary [dangerous]
ruby expressions)?

Regards.


-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net 
aliases: basile<at>tunes<dot>org = bstarynk<at>nerim<dot>net
8, rue de la Fa?encerie, 92340 Bourg La Reine, France