Class: Glark::IO::Lines
- Inherits:
-
Object
- Object
- Glark::IO::Lines
- Defined in:
- lib/glark/util/io/lines.rb
Overview
Lines of input. Handles non-default (“n”) record separator.
Direct Known Subclasses
Instance Method Summary collapse
-
#count ⇒ Object
this reads the entire file and returns the number of lines.
-
#get_line(lnum) ⇒ Object
Returns the given line for this file.
-
#initialize(fname) ⇒ Lines
constructor
A new instance of Lines.
Constructor Details
#initialize(fname) ⇒ Lines
Returns a new instance of Lines.
9 10 11 12 |
# File 'lib/glark/util/io/lines.rb', line 9 def initialize fname @fname = fname @count = nil end |
Instance Method Details
#count ⇒ Object
this reads the entire file and returns the number of lines
21 22 23 24 25 26 |
# File 'lib/glark/util/io/lines.rb', line 21 def count unless @count @count = ::IO::readlines(@fname).size end @count end |
#get_line(lnum) ⇒ Object
Returns the given line for this file. For this method, a line ends with a CR, as opposed to the “lines” method, which ends with $/.
16 17 18 |
# File 'lib/glark/util/io/lines.rb', line 16 def get_line lnum get_lines[lnum] end |