Class: IRuby::OStream
- Inherits:
-
Object
- Object
- IRuby::OStream
- Defined in:
- lib/iruby/ostream.rb
Overview
IO-like object that publishes to 0MQ socket.
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(session, socket, name) ⇒ OStream
constructor
A new instance of OStream.
- #isatty ⇒ Object (also: #tty?)
- #puts(s) ⇒ Object
- #read(*args) ⇒ Object (also: #next, #readline)
- #write(s) ⇒ Object
- #writelines(lines) ⇒ Object
Constructor Details
#initialize(session, socket, name) ⇒ OStream
Returns a new instance of OStream.
4 5 6 7 8 |
# File 'lib/iruby/ostream.rb', line 4 def initialize(session, socket, name) @session = session @socket = socket @name = name end |
Instance Method Details
#close ⇒ Object
10 11 12 |
# File 'lib/iruby/ostream.rb', line 10 def close @socket = nil end |
#flush ⇒ Object
14 15 |
# File 'lib/iruby/ostream.rb', line 14 def flush end |
#isatty ⇒ Object Also known as: tty?
17 18 19 |
# File 'lib/iruby/ostream.rb', line 17 def isatty false end |
#puts(s) ⇒ Object
34 35 36 |
# File 'lib/iruby/ostream.rb', line 34 def puts(s) write "#{s}\n" end |
#read(*args) ⇒ Object Also known as: next, readline
22 23 24 |
# File 'lib/iruby/ostream.rb', line 22 def read(*args) raise IOError, 'not opened for reading' end |
#write(s) ⇒ Object
28 29 30 31 32 |
# File 'lib/iruby/ostream.rb', line 28 def write(s) raise 'I/O operation on closed file' unless @socket @session.send(@socket, 'stream', { name: @name, data: s.to_s }) nil end |
#writelines(lines) ⇒ Object
38 39 40 |
# File 'lib/iruby/ostream.rb', line 38 def writelines(lines) lines.each { |s| write(s) } end |