From: Joel VanderWerf Date: 2006-01-26T04:36:09+09:00 Subject: Re: String#de_inspect (and Kernel#suspicious) Erik Veenstra wrote: > If you do an inspect on a collection of Ruby objects, like a > hash, you end up with a string. It's possible to store this > string in a file, read it again somewhere in the future, > evaluate it and end up with the same collection of Ruby objects > in core. > > So I've written this String#de_inspect, which uses > Kernel#suspicious (slow!) to avoid any malicious code from > being evaluated. > > A kind of human-readable marshaling. That is-human-readable is > important, for me, in this situation. > > (You can only dump objects which inspect to Ruby code, e.g. > Strings, Numerics, Symbols, Arrays, Hashes, nil, true and > false.) For the object->string direction, it may be useful to use amarshal, rather than inspect: http://cvs.m17n.org/~akr/amarshal/ One advantage is with cyclic references. Using #inspect will not preserve enough information to reconstruct the reference. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407