Module: TraceLineNumbers

Defined in:
lib/tracelines.rb

Class Method Summary collapse

Class Method Details

.lnums_for_file(file, uniq = true) ⇒ Object

Return an array of lines numbers that could be stopped at given a file name of a Ruby program.



34
35
36
37
# File 'lib/tracelines.rb', line 34

def lnums_for_file(file, uniq=true)
  lnums_for_iseq(RubyVM::InstructionSequence::compile_file(file),
                 uniq)
end

.lnums_for_iseq(orig_iseq, uniq = true) ⇒ Object



24
25
26
27
28
29
# File 'lib/tracelines.rb', line 24

def lnums_for_iseq(orig_iseq, uniq=true)
  lnums = orig_iseq.child_iseqs.map { |iseq|
    iseq.offsetlines.values.flatten
  }.flatten.sort
  uniq ? lnums.uniq : lnums
end

.lnums_for_str(string, uniq = true) ⇒ Object

Return an array of lines numbers that could be stopped at given a string.



42
43
44
45
# File 'lib/tracelines.rb', line 42

def lnums_for_str(string, uniq=true)
  lnums_for_iseq(RubyVM::InstructionSequence::compile(string),
                 uniq)
end

.lnums_for_str_array(string_array, newline = '', uniq = true) ⇒ Object

Return an array of lines numbers that could be stopped at given a string array.



50
51
52
# File 'lib/tracelines.rb', line 50

def lnums_for_str_array(string_array, newline='', uniq=true)
  lnums_for_str(string_array.join(newline))
end