Top Level Namespace

Defined Under Namespace

Modules: PDRuby

Instance Method Summary collapse

Instance Method Details

#pd(thing = nil, options = {}) ⇒ Object



19
20
21
22
# File 'lib/pd_ruby/helper_methods.rb', line 19

def pd(thing = nil, options = {})
  options[:backtrace_offset] ||= 1
  print_debug(thing, **options)
end


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pd_ruby/helper_methods.rb', line 3

def print_debug(thing = nil, backtrace_offset: 0, **keywords)
  backtrace_line = caller[backtrace_offset].split(':')[0..1].join(':')
  thing = keywords if thing.eql?(nil) && keywords.any?
  thing = thing.inspect unless thing.is_a?(String)
  color = PDRuby.color_for(backtrace_line)

  puts(
    (
      'PD: ' + thing
    ).colorize(color) +
      ' @ ' + backtrace_line.to_s.colorize(color)
  )
  puts "\n"
  thing
end