Class: Fnf::Fifo

Inherits:
Object
  • Object
show all
Defined in:
lib/fnf/fifo.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Fifo

Returns a new instance of Fifo.



4
5
6
7
8
9
10
# File 'lib/fnf/fifo.rb', line 4

def initialize(file)
  if !File.exists?(file)
    File.mkfifo(file)
    File.chmod(0666, file)
  end
  @pipe = File.open(file, "r+")
end

Instance Method Details

#read(n) ⇒ Object



24
25
26
# File 'lib/fnf/fifo.rb', line 24

def read(n)
  @pipe.read(n)
end

#readlineObject



12
13
14
15
16
17
18
# File 'lib/fnf/fifo.rb', line 12

def readline
  str = ""
  while ($_ = self.read(1)) != "\n"
    str << $_
  end
  str << "\n"
end

#to_ioObject



20
21
22
# File 'lib/fnf/fifo.rb', line 20

def to_io
  @pipe.to_io
end