Class: Cosmos::IoMultiplexer
Overview
Adds IO streams and then defers to the streams when using any of the Ruby output methods such as print, puts, etc.
Instance Method Summary collapse
- #add_stream(stream) ⇒ Object
-
#flush ⇒ Object
Calls flush on each stream.
-
#initialize ⇒ IoMultiplexer
constructor
Create the empty stream array.
- #print(*args) ⇒ Object
- #printf(*args) ⇒ Object
- #putc(object) ⇒ Object
- #puts(*args) ⇒ Object
-
#remove_default_io ⇒ Object
Removes STDOUT and STDERR from the array of streams.
- #remove_stream(stream) ⇒ Object
-
#write(string) ⇒ Integer
The length of the string argument.
-
#write_nonblock(string) ⇒ Integer
The length of the string argument.
Constructor Details
#initialize ⇒ IoMultiplexer
Create the empty stream array
18 19 20 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 18 def initialize @streams = [] end |
Instance Method Details
#add_stream(stream) ⇒ Object
78 79 80 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 78 def add_stream(stream) @streams << stream unless @streams.include?(stream) end |
#flush ⇒ Object
Calls flush on each stream
51 52 53 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 51 def flush @streams.each {|stream| stream.flush} end |
#print(*args) ⇒ Object
24 25 26 27 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 24 def print(*args) @streams.each {|stream| stream.print(*args)} nil end |
#printf(*args) ⇒ Object
31 32 33 34 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 31 def printf(*args) @streams.each {|stream| stream.printf(*args)} nil end |
#putc(object) ⇒ Object
38 39 40 41 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 38 def putc(object) @streams.each {|stream| stream.putc(object)} object end |
#puts(*args) ⇒ Object
45 46 47 48 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 45 def puts(*args) @streams.each {|stream| stream.puts(*args)} nil end |
#remove_default_io ⇒ Object
Removes STDOUT and STDERR from the array of streams
72 73 74 75 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 72 def remove_default_io @streams.delete(STDOUT) @streams.delete(STDERR) end |
#remove_stream(stream) ⇒ Object
83 84 85 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 83 def remove_stream(stream) @streams.delete(stream) end |
#write(string) ⇒ Integer
Returns The length of the string argument.
58 59 60 61 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 58 def write(string) @streams.each {|stream| stream.write(string)} string.length end |
#write_nonblock(string) ⇒ Integer
Returns The length of the string argument.
66 67 68 69 |
# File 'lib/cosmos/io/io_multiplexer.rb', line 66 def write_nonblock(string) @streams.each {|stream| stream.write_nonblock(string)} string.length end |