module DebugPrint
because this uses binding_of_caller, it should only be used in development
Constants
- VERSION
Public Class Methods
debug_output(&debug_output_block)
click to toggle source
Set a block to be used for debug output. Call the Rails logger, write to a DB, etc. debug_output
do |output|
::Rails.logger.debug output
end
# File lib/debug_print.rb, line 20 def self.debug_output(&debug_output_block) @@debug_output_block = debug_output_block end
out(value)
click to toggle source
Output a result via the debug_output
configuration, or
# File lib/debug_print.rb, line 25 def self.out(value) if @@debug_output_block @@debug_output_block.call value else puts value end end
Private Instance Methods
d(expression)
click to toggle source
Takes an expression (variable, etc.) and evaluates it in the binding of the caller. Then it does a debug printing the variable name, and value
# File lib/debug_print.rb, line 36 def d(expression) result = binding.of_caller(1).eval(expression.to_s) inspection = result.inspect if result.inspect.length < 50 sout = "\t<#{result.class.name}> #{expression} = #{inspection}" else sout = "\n<#{result.class.name}> #{expression} =\n" sout += inspection + "\n\n" end DebugPrint.out(sout) end