On 5/18/05, Basile Starynkevitch [news] <basile-news / starynkevitch.net> wrote:
> On 2005-05-18, Jacob Fugal <lukfugl / gmail.com> wrote:
> > What you probably need is eval:
> 
> A big thanks for this suggestion!

You're welcome :)
 
> > 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)?

Unfortunately no. A possibility would be to write an encapsulating
method using a regex to verify the input:

  def unescapeString( str )
    raise TypeError, "Argument must be 'just a string'" unless
      str =~ /some nasty regex/
    eval( str )
  end

I don't really want to deal with writing that regex, though, so I'll
leave it as an exercise for the reader. :)

Jacob Fugal