Class: IRuby::OStream

Inherits:
Object
  • Object
show all
Defined in:
lib/iruby/ostream.rb

Overview

IO-like object that publishes to 0MQ socket.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session, name) ⇒ OStream

Returns a new instance of OStream.



6
7
8
# File 'lib/iruby/ostream.rb', line 6

def initialize(session, name)
  @session, @name = session, name
end

Instance Attribute Details

#syncObject

Returns the value of attribute sync.



4
5
6
# File 'lib/iruby/ostream.rb', line 4

def sync
  @sync
end

Instance Method Details

#closeObject



10
11
12
# File 'lib/iruby/ostream.rb', line 10

def close
  @session = nil
end

#flushObject



14
15
# File 'lib/iruby/ostream.rb', line 14

def flush
end

#isattyObject Also known as: tty?



17
18
19
# File 'lib/iruby/ostream.rb', line 17

def isatty
  false
end

#puts(*lines) ⇒ Object



36
37
38
39
40
# File 'lib/iruby/ostream.rb', line 36

def puts(*lines)
  lines = [''] if lines.empty?
  lines.each { |s| write("#{s}\n")}
  nil
end

#read(*args) ⇒ Object Also known as: next, readline

Raises:

  • (IOError)


22
23
24
# File 'lib/iruby/ostream.rb', line 22

def read(*args)
  raise IOError, 'not opened for reading'
end

#write(s) ⇒ Object Also known as: <<, print



28
29
30
31
32
# File 'lib/iruby/ostream.rb', line 28

def write(s)
  raise 'I/O operation on closed file' unless @session
  @session.send(:publish, :stream, name: @name, text: s.to_s)
  nil
end

#writelines(lines) ⇒ Object



42
43
44
# File 'lib/iruby/ostream.rb', line 42

def writelines(lines)
  lines.each { |s| write(s) }
end