Method: Parser::Source::Buffer#line_range

Defined in:
lib/parser/source/buffer.rb

#line_range(lineno) ⇒ Range

Extract line lineno as a new Range, taking first_line into account.

Parameters:

  • lineno (Integer)

Returns:

Raises:

  • (IndexError)

    if lineno is out of bounds


289
290
291
292
293
294
295
296
297
298
# File 'lib/parser/source/buffer.rb', line 289

def line_range(lineno)
  index = lineno - @first_line
  if index < 0 || index + 1 >= line_begins.size
    raise IndexError, 'Parser::Source::Buffer: range for line ' \
      "#{lineno} requested, valid line numbers are #{@first_line}.." \
      "#{@first_line + line_begins.size - 2}"
  else
    Range.new(self, line_begins[index], line_begins[index + 1] - 1)
  end
end