Forum: Ruby unescape result from inspect

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2013-10-18 16:15
how can i unescape the results from inspect method. I tried with URI but
not lucky :(

x={"a"=>"aaaaaaaaaaaaaa","b"=>"ññññækkksdlæp@"}
puts URI.unescape(x.inspect)
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-10-18 17:20
(Received via mailing list)
On Fri, Oct 18, 2013 at 4:15 PM, Mario Ruiz <lists@ruby-forum.com>
wrote:
> how can i unescape the results from inspect method. I tried with URI but
> not lucky :(
>
> x={"a"=>"aaaaaaaaaaaaaa","b"=>"kkksdlp@"}
> puts URI.unescape(x.inspect)

Why do you expect that to work at all?  URI escaping != #inspect format.

Cheers

robert
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2013-10-18 17:21
So.... no possible to be unescaped?

Robert Klemme wrote in post #1124848:
> On Fri, Oct 18, 2013 at 4:15 PM, Mario Ruiz <lists@ruby-forum.com>
> wrote:
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2013-10-29 17:06
The problem is I have values escaped with inspect stored on Database and
later on I need to recover them and unescape them to be used... any
idea?
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2013-10-29 17:44
(Received via mailing list)
On Tue, Oct 29, 2013 at 5:06 PM, Mario Ruiz <lists@ruby-forum.com>
wrote:
> The problem is I have values escaped with inspect stored on Database and
> later on I need to recover them and unescape them to be used... any
> idea?

The approach is broken: #inspect's format is not intended for
serialization.  You need to use a different mechanism to serialize
your objects into and out of the database:

 - Marshal (binary)
 - YAML (text)
 - some form of XML serialization
 - some form of JSON serialization

Cheers

robert
This topic is locked and can not be replied to.