Class: PipeDream

Inherits:
Object
  • Object
show all
Defined in:
lib/multitest/pipe_dream.rb

Instance Method Summary collapse

Constructor Details

#initializePipeDream

Returns a new instance of PipeDream.



2
3
4
5
# File 'lib/multitest/pipe_dream.rb', line 2

def initialize
  @child_read, @parent_write = IO.pipe
  @parent_read, @child_write = IO.pipe
end

Instance Method Details

#closeObject



35
36
37
38
# File 'lib/multitest/pipe_dream.rb', line 35

def close
  done_reading
  done_writing
end

#done_readingObject



44
45
46
# File 'lib/multitest/pipe_dream.rb', line 44

def done_reading
  @reader.close unless @reader.closed?
end

#done_writingObject



40
41
42
# File 'lib/multitest/pipe_dream.rb', line 40

def done_writing
  @writer.close unless @writer.closed?
end

#eof?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/multitest/pipe_dream.rb', line 17

def eof?
  @reader.eof?
end

#getsObject



7
8
9
# File 'lib/multitest/pipe_dream.rb', line 7

def gets
  @reader.gets
end

#identify_as_childObject



21
22
23
24
25
26
# File 'lib/multitest/pipe_dream.rb', line 21

def identify_as_child
  @parent_write.close
  @parent_read.close
  @reader = @child_read
  @writer = @child_write
end

#identify_as_parentObject



28
29
30
31
32
33
# File 'lib/multitest/pipe_dream.rb', line 28

def identify_as_parent
  @child_write.close
  @child_read.close
  @reader = @parent_read
  @writer = @parent_write
end

#write(str) ⇒ Object



11
12
13
14
15
# File 'lib/multitest/pipe_dream.rb', line 11

def write(str)
  @writer.write(str)
  @writer.flush
  str
end