It seemed useful to be able to silence more than one stream at a time. # Silences any stream for the duration of the block. # # silence_stream(STDOUT) do # puts ''This will never be seen'' # end # # puts ''But this will'' def silence_stream(*streams) streams = [STDOUT, STDERR] if streams.empty? old = {} streams.each do |stream| old[stream] = stream.dup stream.reopen(RUBY_PLATFORM =~ /mswin/ ? ''NUL:'' : ''/dev/null'') stream.sync = true yield end ensure streams.each do |stream| stream.reopen(old[stream]) end end alias_method :silently, :silence_stream T. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Of course, it would help if I put ''yield'' in the right place. Try again: def silence_stream(*streams) streams = [STDOUT, STDERR] if streams.empty? on_hold = streams.collect{ |stream| stream.dup } streams.each do |stream| stream.reopen(RUBY_PLATFORM =~ /mswin/ ? ''NUL:'' : ''/dev/null'') stream.sync = true end yield ensure streams.each_with_index do |stream, i| stream.reopen(on_hold[i]) end end T. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---