From: matz@... (Yukihiro Matsumoto) Date: 2001-05-22T12:43:14+09:00 Subject: [ruby-talk:15519] Re: StringBuffer IO Class Hi, In message "[ruby-talk:15501] StringBuffer IO Class" on 01/05/22, "Wayne Blair" writes: |Here is pseudocode for what I want to do - I'd be really appreciative if |anyone could help fill in the blanks with ruby code. | |def foo | # redirect stdout to a buffer (buff) | | # do some work that may result in writes to stdout | | # redirect stdout back to original stdout | | # write contents of buff to stdout |end Here is realcode for what you want to do. ;-) def foo # redirect stdout to a buffer (buff) buff = "" def buff.write(str) self << str end $defout = buff # do some work that may result in writes to stdout print "hello world\n" # redirect stdout back to original stdout $defout = STDOUT # write contents of buff to stdout print buff end "write" method is all you need for redirection. matz.