I need a simple way to redirect output from methods defined
in a module, using puts.
module Foo def test puts 'Hello World!' end end class Bar def initialize @string = '' end def add(this_text) @string << this_text end end
In the above example, I would like to be able to redirect the
puts output from the method test, into a new instance of Bar.new
I assume it can somehow be done via re-assigning stdout, and
then restoring it afterwards, using some kind of IO Object
possibly. I have been reading some blog entries but I still
do not understand it - I can easily redirect into a file,
but I do not understand how to redirect into an instance
variable of a given class.