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.



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

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

.lnums_for_iseq(iseq, uniq = true) ⇒ Object



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

def lnums_for_iseq(iseq, uniq=true)
  lnums = 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.



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

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.



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

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