From: Phrogz Date: 2007-04-05T03:05:06+09:00 Subject: Re: Problem Extracting Array Values 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 :)