Module: Kernel

Defined in:
lib/libis/tools/extend/kernel.rb

Overview

Extension class

Instance Method Summary collapse

Instance Method Details

#dputs(value) ⇒ Object

Debugging aid: print “<name> : <value>”

Example:

x = 'abc'
dputs x
# => x : 'abc'


20
21
22
23
# File 'lib/libis/tools/extend/kernel.rb', line 20

def dputs(value)
  name = extract_argstring_from :dputs, caller
  puts "#{name} : '#{value}'"
end

#extract_argstring_from(name, call_stack) ⇒ Object

Debugging aid: extract the name of the argument of the last caller



5
6
7
8
9
10
11
# File 'lib/libis/tools/extend/kernel.rb', line 5

def extract_argstring_from(name, call_stack)
  file, line_number = call_stack.first.match(/^(.+):(\d+)/).captures
  line = File.readlines(file)[line_number.to_i - 1].strip
  argstring = line[/#{name}\s*\(?(.+?)\)?\s*($|#|\[|\})/, 1]
  raise "unable to extract name for #{name} from #{file} line #{line_number}:\n  #{line}" unless argstring
  argstring
end