Class: RemoteRuby::CompatIOReader

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_ruby/compat_io_reader.rb

Overview

Wraps any object that responds to #readpartial with a readable IO object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ CompatIOReader



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/remote_ruby/compat_io_reader.rb', line 8

def initialize(io)
  if io.is_a?(IO)
    @readable = io
    return
  end

  raise 'Object must respond to #readpartial' unless io.respond_to?(:readpartial)

  @readable, @writeable = IO.pipe
  @thread = start(io)
end

Instance Attribute Details

#readableObject (readonly)

Returns the value of attribute readable.



6
7
8
# File 'lib/remote_ruby/compat_io_reader.rb', line 6

def readable
  @readable
end

Instance Method Details

#joinObject



20
21
22
23
24
25
26
# File 'lib/remote_ruby/compat_io_reader.rb', line 20

def join
  return unless @writeable

  @writeable.close
  @thread.join
  @readable.close
end