Method: String#remove_line

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

#remove_line(line_number, separator = $/) ⇒ String

Uses the String each_line method to interate through the lines and removes the line specified.

Parameters:

  • line_number (Integer)

    The line to remove from the string (1 based)

  • separator (String) (defaults to: $/)

    The record separator to pass to #each_line ($/ by default is the newline character)

Returns:

  • (String)

    A new string with the line removed



159
160
161
162
163
164
165
166
167
# File 'lib/openc3/core_ext/string.rb', line 159

def remove_line(line_number, separator = $/)
  new_string = ''
  index = 1
  self.each_line(separator) do |line|
    new_string << line unless index == line_number
    index += 1
  end
  new_string
end