From: James Edward Gray II Date: 2006-09-07T03:17:41+09:00 Subject: Re: How to take output of eval into a string? On Sep 6, 2006, at 12:52 PM, Gareth Adams wrote: > Morton Goldberg ameritech.net> writes: > >> >> On Sep 6, 2006, at 9:02 AM, Anil Wadghule wrote: >> >>> #code >>> a = "puts 'I like Ruby'" >>> b = eval(a) >>> puts b > >> Exactly what are you trying to capture into a string? > > I would guess that the intention is to capture STDOUT and get b == > 'I like Ruby' >> require "stringio" => true >> a = "puts 'I like Ruby'" => "puts 'I like Ruby'" >> b = eval("begin $stdout = StringIO.new; #{a}; $stdout.string; ensure $stdout = STDOUT end") => "I like Ruby\n" Hope that helps. James Edward Gray II