Class: Peruby::IOHandle
- Inherits:
-
Object
- Object
- Peruby::IOHandle
- Defined in:
- lib/peruby/runtime/io_handle.rb
Overview
Perl filehandle state over a Ruby IO object.
Instance Attribute Summary collapse
-
#eof_flag ⇒ Object
Returns the value of attribute eof_flag.
-
#io ⇒ Object
Returns the value of attribute io.
-
#layers ⇒ Object
Returns the value of attribute layers.
-
#lineno ⇒ Object
Returns the value of attribute lineno.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(io, layers: []) ⇒ IOHandle
constructor
A new instance of IOHandle.
- #read_record(separator) ⇒ Object
Constructor Details
#initialize(io, layers: []) ⇒ IOHandle
Returns a new instance of IOHandle.
8 9 10 11 12 13 |
# File 'lib/peruby/runtime/io_handle.rb', line 8 def initialize(io, layers: []) @io = io @lineno = 0 @eof_flag = false @layers = layers end |
Instance Attribute Details
#eof_flag ⇒ Object
Returns the value of attribute eof_flag.
6 7 8 |
# File 'lib/peruby/runtime/io_handle.rb', line 6 def eof_flag @eof_flag end |
#io ⇒ Object
Returns the value of attribute io.
6 7 8 |
# File 'lib/peruby/runtime/io_handle.rb', line 6 def io @io end |
#layers ⇒ Object
Returns the value of attribute layers.
6 7 8 |
# File 'lib/peruby/runtime/io_handle.rb', line 6 def layers @layers end |
#lineno ⇒ Object
Returns the value of attribute lineno.
6 7 8 |
# File 'lib/peruby/runtime/io_handle.rb', line 6 def lineno @lineno end |
Instance Method Details
#close ⇒ Object
30 31 32 33 34 35 |
# File 'lib/peruby/runtime/io_handle.rb', line 30 def close @io.close unless @io.closed? 1 rescue IOError, SystemCallError '' end |
#read_record(separator) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/peruby/runtime/io_handle.rb', line 15 def read_record(separator) value = if separator.nil? @io.read elsif separator == '' @io.gets("\n\n") elsif separator.is_a?(Ref) && separator.target.is_a?(Scalar) @io.read(Conv.to_num(separator.target.get).to_i) else @io.gets(Conv.to_str(separator)) end @eof_flag = value.nil? @lineno += 1 if value value end |