String.undump

Is there any way to “undump” dumped string?

    => stringWithNonPrintingChars = "£ód¼"
    => a = [32,stringWithNonPrintingChars].inspect
    => puts a
    "[32, \"\\243\\363d\\274\"]"
    => puts a.undump
    £ód¼
···


Szymon Drejewicz

Wrote Szymon Drejewicz drejewic@wsisiz.edu.pl, on Mon, Apr 26, 2004 at 09:59:07PM +0900:

Is there any way to “undump” dumped string?

    => stringWithNonPrintingChars = "??d?"
    => a = [32,stringWithNonPrintingChars].inspect
    => puts a
    "[32, \"\\243\\363d\\274\"]"
    => puts a.undump
    ??d?

eval it:

irb(main):001:0> a = “[32, "\243\363d\274"]”
=> “[32, "\243\363d\274"]”
irb(main):003:0> eval a
=> [32, “\243\363d\274”]

Sam

···


Sam Roberts sroberts@certicom.com

if you need to do it inline:

[1,2].inspect.instance_eval{eval self} == [1,2]
==>true

or write a method:

class String
def undump() eval(self) end
end
==>nil
[1,2].inspect.undump == [1,2]
==>true

cheers,
–Mark

···

On Apr 26, 2004, at 5:59 AM, Szymon Drejewicz wrote:

Is there any way to “undump” dumped string?

    => stringWithNonPrintingChars = "Łódź"
    => a = [32,stringWithNonPrintingChars].inspect
    => puts a
    "[32, \"\\243\\363d\\274\"]"
    => puts a.undump
    Łódź