Module: TraceLineNumbers

### Home Classes Methods

### In Files

- lib/tracelines19.rb

### Methods

- ::lnums_for_file
- ::lnums_for_str
- ::lnums_for_str_array

### Class/Module Index

Quicksearch

- Debugger
- Debugger::Linecache
- LineCache
- Object
- TraceLineNumbers

No matching classes.

# TraceLineNumbers

$Id$

### Public Class Methods

lnums_for_file(file) click to toggle source

    # File lib/tracelines19.rb, line 24
    def lnums_for_file(file)
      lnums_for_str(File.read(file))
    end

lnums_for_str(src) click to toggle source

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

    # 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='') click to toggle source

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.

    # File lib/tracelines19.rb, line 33
    def lnums_for_str_array(string_array, newline='')
      lnums_for_str(string_array.join(newline))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.