How to save an irb session including the command output to a file

Hi,
I noticed from google there are many methods to save irb command history
to a file, but is there a method to save both the command history and
command output to a file when exiting irb?
For example, the red lines should also be saved.
irb(main):001:0> class Airb(main):002:1> puts "hello
world"irb(main):003:1> endhello world=> nilirb(main):004:0>

I tried to use “irb | tee irb.log”, but seems there will be unreadable
character displayed when using “Arrow keys”.
Thanks,Brian

script mylog.txt
irb

do stuff
^D
exit

On Fri, Jul 13, 2012 at 9:24 PM, Brian C. [email protected]
wrote:

script mylog.txt
irb

do stuff
^D
exit

As far as I can see that will save meta characters (escape sequences
for color control etc.) as well - similarly to the variant with tee.
Solution for that would be to use strings to extract only readable
characters from the log.

Kind regards

robert