Sha256: 28cee6a779eef4178fde8e6e6600dee88920ee2d8896a97547e3536f64ad3edf

Contents?: true

Size: 1.35 KB

Versions: 6

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby
# $Id: tracelines.rb 36 2008-01-23 12:07:02Z rockyb $
begin require 'rubygems' rescue LoadError end
# require 'ruby-debug' ; Debugger.start

module TraceLineNumbers
  @@SRC_DIR = File.expand_path(File.dirname(__FILE__))
  require File.join(@@SRC_DIR, '..', 'ext', 'trace_nums')

  # Return an array of lines numbers that could be 
  # stopped at given a file name of a Ruby program.
  def lnums_for_file(file)
    lnums_for_str(File.read(file))
  end
  module_function :lnums_for_file

  # 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.
  def lnums_for_str_array(string_array, newline='')
    lnums_for_str(string_array.join(newline))
  end
  module_function :lnums_for_str_array
end

if __FILE__ == $0
  SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
  # test_file = '../test/rcov-bug.rb'
  test_file = '../test/lnum-data/begin1.rb'
  if  File.exists?(test_file)
    puts TraceLineNumbers.lnums_for_file(test_file).inspect 
    load(test_file, 0) # for later
  end
  puts TraceLineNumbers.lnums_for_file(__FILE__).inspect
  unless SCRIPT_LINES__.empty?
    key = SCRIPT_LINES__.keys.first
    puts key
    puts SCRIPT_LINES__[key]
    puts TraceLineNumbers.lnums_for_str_array(SCRIPT_LINES__[key]).inspect
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
linecache-0.42-mswin32 lib/tracelines.rb
linecache-0.41-mswin32 lib/tracelines.rb
linecache-0.42 lib/tracelines.rb
linecache-0.4 lib/tracelines.rb
linecache-0.41 lib/tracelines.rb
linecache-0.3 lib/tracelines.rb