Method: String#num_lines

Defined in:
lib/openc3/core_ext/string.rb

#num_linesInteger

Returns The number of lines in the string (as split by the newline character).

Returns:

  • (Integer)

    The number of lines in the string (as split by the newline character)



171
172
173
174
175
# File 'lib/openc3/core_ext/string.rb', line 171

def num_lines
  value = self.count("\n")
  value += 1 if self[-1..-1] and self[-1..-1] != "\n"
  value
end