String.undump

S

Szymon Drejewicz

Is there any way to "undump" dumped string?

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

Sam Roberts

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
 
M

Mark Hubbart

Is there any way to "undump" dumped string?

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,145
Messages
2,570,825
Members
47,371
Latest member
Brkaa

Latest Threads

Top