When developing & debugging, I sometimes wish I could write a 1-liner that dumped the names, types & values of a bunch of variables. The problem is I don't know how to access the name of a variable, if I can at all.
Here is a first attempt:
foo = 1
bar = "42"
baz = Hash.new
[foo, bar, baz].each do |v|
puts "#{v.???} = (#{v.class}) #{v}"
end
I'd like the output of this program to be something like:
foo = (Fixnum) 1
bar = (String) 42
baz = (Hash) ...
I don't know what ???
should be above. Can this be done?