Class: Debtective::Comments::FindEndOfStatement

Inherits:
Object
  • Object
show all
Defined in:
lib/debtective/comments/find_end_of_statement.rb

Overview

Find the index of the line ending a statement

Examples:

FindEndOfStatement.new(
  [
    "class User",
    "  def example",
    "    x + y",
    "  end"
    "end"
  ],
  1
).call
=> 3

Instance Method Summary collapse

Constructor Details

#initialize(lines:, first_line_index:) ⇒ FindEndOfStatement

Returns a new instance of FindEndOfStatement.

Parameters:

  • lines (Array<String>)

    lines of code

  • first_line_index (Integer)

    index of the statement first line



23
24
25
26
# File 'lib/debtective/comments/find_end_of_statement.rb', line 23

def initialize(lines:, first_line_index:)
  @lines = lines
  @first_line_index = first_line_index
end

Instance Method Details

#callInteger

Note:

suppress_stderr prevents outputs from RubyVM::InstructionSequence.compile

Returns index of the line ending the statement.

Returns:

  • (Integer)

    index of the line ending the statement



30
31
32
# File 'lib/debtective/comments/find_end_of_statement.rb', line 30

def call
  last_line_index
end