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 ho
foo = 1
bar = "42"
baz = Hash.new
Varspec = Struct.new(:name, :type, :value, :inspect_str) do
def to_s
"#{name} = (#{type}) #{inspect_str}"
end
end
lvars = local_variables.map {|lvar|
lvar = lvar.to_s
val = eval(lvar)
val = val.dup rescue val
Varspec.new(lvar, val.class, val, val.inspect)
}
puts lvars
# baz = (Hash) {}
# bar = (String) "42"
# foo = (Fixnum) 1
Or, you could just use a debugger. That's what they were invented for, after all.