Class: Debtective::FindEndOfStatement

Inherits:
Object
  • Object
show all
Includes:
StderrHelper
Defined in:
lib/debtective/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

Methods included from StderrHelper

#suppress_stderr

Constructor Details

#initialize(lines, first_line_index) ⇒ FindEndOfStatement

Returns a new instance of FindEndOfStatement.

Parameters:

  • lines (Array<String>)

    lines of code

  • index (Integer)

    index of the statement first line



26
27
28
29
# File 'lib/debtective/find_end_of_statement.rb', line 26

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

Instance Method Details

#callInteger

Note:

use suppress_stderr to prevent error outputs from RubyVM::InstructionSequence.compile

index of the line ending the statement

Returns:

  • (Integer)


35
36
37
# File 'lib/debtective/find_end_of_statement.rb', line 35

def call
  suppress_stderr { last_line_index }
end