Class: IOPipe

Inherits:
Object show all
Defined in:
lib/commands/datas/pipe.rb

Overview

Author

Nicolas Pouillard <[email protected]>.

Copyright

Copyright © 2005 Nicolas Pouillard. All rights reserved.

License

GNU General Public License (GPL).

Revision

$Id: /w/fey/ruby_ex/trunk/lib/commands/datas/pipe.rb 21865 2006-02-18T17:13:28.680350Z pouillar $

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIOPipe

Returns a new instance of IOPipe.



8
9
10
11
# File 'lib/commands/datas/pipe.rb', line 8

def initialize
  @reader, @writer = IO.pipe
  @open_mode = :w
end

Instance Attribute Details

#open_modeObject

Returns the value of attribute open_mode.



7
8
9
# File 'lib/commands/datas/pipe.rb', line 7

def open_mode
  @open_mode
end

#readerObject

Returns the value of attribute reader.



7
8
9
# File 'lib/commands/datas/pipe.rb', line 7

def reader
  @reader
end

#writerObject

Returns the value of attribute writer.



7
8
9
# File 'lib/commands/datas/pipe.rb', line 7

def writer
  @writer
end

Instance Method Details

#closeObject Also known as: clean



23
24
25
26
# File 'lib/commands/datas/pipe.rb', line 23

def close
  @reader.close
  @writer.close
end

#open(mode = :r) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/commands/datas/pipe.rb', line 12

def open ( mode=:r )
  case mode.to_sym
    when :r
      @writer.close
      @reader
    when :w
      @reader.close
      @writer
    else raise ArgumentError, "Bad open mode: #{mode.inspect}"
  end
end

#readObject



31
32
33
# File 'lib/commands/datas/pipe.rb', line 31

def read
  open.read
end

#to_io_for_commandsObject



28
29
30
# File 'lib/commands/datas/pipe.rb', line 28

def to_io_for_commands
  open(open_mode)
end