Get The Name Of A Local Variable

前端 未结 4 708
逝去的感伤
逝去的感伤 2020-12-30 11:43

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

4条回答
  •  甜味超标
    2020-12-30 11:57

    foo = 1
    bar = "42"
    baz = Hash.new
    
    %w(foo bar baz).each do |vn|
        v = eval(vn)
        puts "#{vn} = (#{v.class}) #{v}"
    end
    

    But this, of course, doesn't help you if you want a method with 1 argument.

提交回复
热议问题