Module: TraceLineNumbers
- Defined in:
- lib/tracelines.rb
Overview
Copyright © 2007, 2008, 2009, 2010, 2014
Rocky Bernstein <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Class Method Summary collapse
-
.lnums_for_file(file) ⇒ Object
Return an array of lines numbers that could be stopped at given a file name of a Ruby program.
- .lnums_for_str(src) ⇒ Object
-
.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.
Class Method Details
.lnums_for_file(file) ⇒ Object
Return an array of lines numbers that could be stopped at given a file name of a Ruby program.
40 41 42 |
# File 'lib/tracelines.rb', line 40 def lnums_for_file(file) lnums_for_str(File.read(file)) end |
.lnums_for_str(src) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tracelines.rb', line 22 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 = '', uniq = true) ⇒ Object
Return an array of lines numbers that could be stopped at given a string array.
47 48 49 |
# File 'lib/tracelines.rb', line 47 def lnums_for_str_array(string_array, newline='', uniq=true) lnums_for_str(string_array.join(newline)) end |