Class: IO::Stream::Generic

Inherits:
Object
  • Object
show all
Includes:
Readable, Writable
Defined in:
lib/io/stream/generic.rb

Overview

Base class for stream implementations providing common functionality.

Direct Known Subclasses

Buffered

Constant Summary

Constants included from Writable

Writable::ASYNC_SAFE

Constants included from Readable

Readable::ASYNC_SAFE

Instance Attribute Summary

Attributes included from Writable

#minimum_write_size

Attributes included from Readable

#minimum_read_size

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Writable

#<<, #close_write, #flush, #puts, #write

Methods included from Readable

#block_size, #block_size=, #close_read, #discard_until, #finish!, #finished?, #gets, #peek, #read, #read_exactly, #read_partial, #read_until, #readable?, #readpartial

Constructor Details

#initialize(**options) ⇒ Generic

Initialize a new generic stream.



31
32
33
# File 'lib/io/stream/generic.rb', line 31

def initialize(**options)
  super(**options)
end

Class Method Details

.async_safe?(method) ⇒ Boolean

Check if a method is async-safe.

Returns:

  • (Boolean)


25
26
27
# File 'lib/io/stream/generic.rb', line 25

def self.async_safe?(method)
  Readable.async_safe?(method) || Writable.async_safe?(method)
end

Instance Method Details

#closeObject

Best effort to flush any unwritten data, and then close the underling IO.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/io/stream/generic.rb', line 42

def close
  return if closed?
  
  begin
    self.flush
  rescue
    # We really can't do anything here unless we want #close to raise exceptions.
  ensure
    self.sysclose
  end
end

#closed?Boolean

Check if the stream is closed.

Returns:

  • (Boolean)


37
38
39
# File 'lib/io/stream/generic.rb', line 37

def closed?
  false
end