From: ara.t.howard@... Date: 2007-04-05T04:17:32+09:00 Subject: Re: Problem Extracting Array Values On Thu, 5 Apr 2007, Phrogz wrote: > On Apr 4, 11:34 am, Brian Candler wrote: >> On Thu, Apr 05, 2007 at 01:05:44AM +0900, Dustin Anderson wrote: >>> is there a simple way in ruby to build an array from a string like this: >> >>> block1,block2,block3 to an array that is like this: >> >>> ["block1", "block2", "block3"] >> >> I always thought that Object#inspect could be considered as a (crude) form >> of object serialisation, and it would be really useful to have a reverse >> "uninspect" operation to recreate the object from it again. Has anyone >> written such a parser? > > irb(main):001:0> a1 = ["foo",/bar/,42,false,nil] > => ["foo", /bar/, 42, false, nil] > irb(main):002:0> s = a1.inspect > => "[\"foo\", /bar/, 42, false, nil]" > irb(main):003:0> a2 = eval(s) > => ["foo", /bar/, 42, false, nil] > irb(main):004:0> a1 == a2 > => true > > So: > > class String > def uninspect > eval(self) > end > end yeah. maybe class String def uninspect Thread.new { $SAFE=4 begin eval self rescue Exception => e e end } end end though. -a -- be kind whenever possible... it is always possible. - the dalai lama