# frozen_string_literal: true # encoding=utf-8 require 'pp' $debug = $DEBUG || !ENV['WW'].nil? # attribution in output unless disabled if $debug && ENV['WW_MINIMUM'].nil? $stderr.puts "WW Debugging per $DEBUG ('ruby --debug')" if $DEBUG $stderr.puts "WW Debugging per environment variable WW" if !ENV['WW'].nil? end # def wtr(*objs, full_backtrace: false, single_line: false) # ww(['->'] + objs, # locations: caller_locations[2..-1], # full_backtrace: full_backtrace, # single_line: single_line) # end def ww(*objs, full_backtrace: false, single_line: false, locations: caller_locations) return unless $debug def cil(caller_info) "#{caller_info.lineno} : #{File.basename(caller_info.path)} : " \ "#{caller_info.label}" end backtrace = if full_backtrace locations.map do |caller_info| cil(caller_info) end else [cil(locations[0, 1].first)] end trace = backtrace + objs if single_line PP.singleline_pp(trace, $stderr) else PP.pp(trace, $stderr) end end