From: John Kaurin Date: 2001-11-17T04:27:24+09:00 Subject: [ruby-talk:25614] Re: Trashing $defout | Well, in this case you must do the same thing with $stdout | | pigeon% cat b.rb | #!/usr/bin/ruby | def trash | | begin | defout = $defout | $defout = File.open('/dev/null', 'w+') | yield | ensure | $defout.reopen(defout) | end | | end | | trash do | $stdout.puts "hello !" | end | pigeon% b.rb | hello ! | pigeon% | | | | Guy Decoux You are correct. I meant to remove the $stdout wording before posting :-( I actually use $stdout.puts to override the trash for debugging code wrapped by trash. I would normally write code witout the $stdout in which case trash works fine (on Windows and UNIX at least). The output would (should) be trashed with the following code. def trash begin defout = $defout $defout = File.open('/dev/null', 'w+') yield ensure $defout.reopen(defout) end end trash do puts "hello !" # Remove $stdout. from Guy's code. end