Class: Glark::IO::Lines

Inherits:
Object
  • Object
show all
Defined in:
lib/glark/util/io/lines.rb

Overview

Lines of input. Handles non-default (“n”) record separator.

Direct Known Subclasses

LinesCR, LinesNonCR

Instance Method Summary collapse

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

#countObject

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