From: Chris Pine Date: 2002-12-30T03:22:31+09:00 Subject: capturing puts in mod_ruby Hello, In order to run code samples for the tutorial I am writing, I essentially do the following: strIO = StringIO.new if !input.empty? input = input.join("\n")+"\n" input = StringIO.new (input, "r") class << strIO; self; end.class_eval do ['gets', 'getc', 'read'].each do |meth| define_method(meth) do inStr = input.method(meth).call puts inStr.chomp # Echo input. inStr end end end end strIO.instance_eval code This works pretty well. However, what if the code I was trying to run did something like this? class Foo def foo puts 'Foo#foo was called.' end end Foo.new.foo This is not doing the StringIO puts, but the Kernel puts instead. (Actually, it does some sort of special mod_ruby puts which spits the output straight to the browser, which REALLY screws things up for me.) Anyone know how to fix something like this? Perhaps I can do something like mod_ruby does (redefining puts), but how is mod_ruby doing it? Many thanks for any help, Chris