Skip to content

Instantly share code, notes, and snippets.

@markburns
Last active March 10, 2016 09:51
Show Gist options
  • Save markburns/ec04333e243282afca7b to your computer and use it in GitHub Desktop.
Save markburns/ec04333e243282afca7b to your computer and use it in GitHub Desktop.
dbg.rb
require "binding_of_caller"
class BasicObject
def dbg(variable_name=nil)
puts ">" * 80
other_binding = binding.of_caller(1)
vars =
other_binding.eval("local_variables") +
other_binding.eval("instance_variables")
variable_name ||= vars.
reject{|v| v == :_}.
detect { |v| other_binding.eval(v.to_s) == self }
if variable_name
puts "#{variable_name}: #{self.inspect}"
else
puts self.inspect
end
puts "<" * 80
self
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment