Module: TraceLineNumbers
- Defined in:
- lib/tracelines19.rb
Overview
$Id$
Class Method Summary collapse
- .lnums_for_file(file) ⇒ Object
-
.lnums_for_str(src) ⇒ Object
Return an array of lines numbers that could be stopped at given a file name of a Ruby program.
-
.lnums_for_str_array(string_array, newline = '') ⇒ Object
Return an array of lines numbers that could be stopped at given a file name of a Ruby program.
Class Method Details
.lnums_for_file(file) ⇒ Object
24 25 26 |
# File 'lib/tracelines19.rb', line 24 def lnums_for_file(file) lnums_for_str(File.read(file)) end |
.lnums_for_str(src) ⇒ Object
Return an array of lines numbers that could be stopped at given a file name of a Ruby program.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tracelines19.rb', line 8 def self.lnums_for_str src name = "#{Time.new.to_i}_#{rand(2**31)}" iseq = RubyVM::InstructionSequence.compile(src, name) lines = {} iseq.disasm.each_line{|line| if /^\d+ (\w+)\s+.+\(\s*(\d+)\)$/ =~ line insn = $1 lineno = $2.to_i next unless insn == 'trace' lines[lineno] = true # p [lineno, line] end } lines.keys end |
.lnums_for_str_array(string_array, newline = '') ⇒ Object
Return an array of lines numbers that could be stopped at given a file name of a Ruby program. We assume the each line has n at the end. If not set the newline parameters to n.
33 34 35 |
# File 'lib/tracelines19.rb', line 33 def lnums_for_str_array(string_array, newline='') lnums_for_str(string_array.join(newline)) end |