Class: IO::Stream::Buffered
Instance Attribute Summary collapse
Attributes inherited from Generic
#block_size
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Generic
#<<, #close, #eof!, #eof?, #flush, #gets, #peek, #puts, #read, #read_exactly, #read_partial, #read_until, #readpartial, #write
Constructor Details
#initialize(io) ⇒ Buffered
Returns a new instance of Buffered.
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/io/stream/buffered.rb', line 40
def initialize(io, ...)
super(...)
@io = io
if io.respond_to?(:timeout)
@timeout = io.timeout
else
@timeout = nil
end
end
|
Instance Attribute Details
#io ⇒ Object
Returns the value of attribute io.
51
52
53
|
# File 'lib/io/stream/buffered.rb', line 51
def io
@io
end
|
Class Method Details
.open(path, mode = "r+", **options) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/io/stream/buffered.rb', line 10
def self.open(path, mode = "r+", **options)
stream = self.new(::File.open(path, mode), **options)
return stream unless block_given?
begin
yield stream
ensure
stream.close
end
end
|
.wrap(io, **options) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/io/stream/buffered.rb', line 22
def self.wrap(io, **options)
if io.respond_to?(:buffered=)
io.buffered = false
else
io.sync = true
end
stream = self.new(io, **options)
return stream unless block_given?
begin
yield stream
ensure
stream.close
end
end
|
Instance Method Details
#close_read ⇒ Object
57
58
59
|
# File 'lib/io/stream/buffered.rb', line 57
def close_read
@io.close_read
end
|
#close_write ⇒ Object
61
62
63
64
65
|
# File 'lib/io/stream/buffered.rb', line 61
def close_write
super
ensure
@io.close_write
end
|
#closed? ⇒ Boolean
53
54
55
|
# File 'lib/io/stream/buffered.rb', line 53
def closed?
@io.closed?
end
|
#readable? ⇒ Boolean
67
68
69
|
# File 'lib/io/stream/buffered.rb', line 67
def readable?
super && @io.readable?
end
|