From: Andrew Stewart Date: 2007-10-02T20:02:35+09:00 Subject: Discarding putc But Not puts Hello, I'm working with a third-party library that calls both putc and puts in a certain method. I'd like to discard what is written with putc for the duration of the method while keeping anything written to puts. Given that the method lets you hook in your own code at its start and end, how do I do this? I've tried various approaches including replacing $stdout with a custom class, and opening $stdout and rewriting putc -- but I haven't quite succeeded. For example, here's some code that doesn't work: class << $stdout alias :original_putc :putc def putc(obj) end end >> putc 'b' => "b" # I was hoping for no output And some more non-working code: class MyIO < StringIO def putc(obj) end end # In hook called at start of target method $original_stdout = $stdout $stdout = MyIO.new # In hook called at end of target method $stdout = $original_stdout Result: both putc and puts appear to be discarded. Could anyone please show me the light? Thanks in advance, Andy Stewart ------- http://airbladesoftware.com