Module: IoInterceptor
- Defined in:
- lib/dolzenko/io_interceptor.rb
Overview
Safe way to intercept IO stream where just replacing STDOUT doesn’t work: rubyforge.org/tracker/index.php?func=detail&aid=5217&group_id=426&atid=1698
Instance Method Summary collapse
Instance Method Details
#intercept ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dolzenko/io_interceptor.rb', line 6 def intercept begin @intercept = true @intercepted = "" yield ensure @intercept = false end @intercepted end |
#supress ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/dolzenko/io_interceptor.rb', line 17 def supress begin @supress = true yield ensure @supress = false end end |
#write(str) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/dolzenko/io_interceptor.rb', line 26 def write(str) if @supress || @intercept @intercepted << str.to_s unless @supress str.size else super end end |