From: Ronnie Aa Date: 2012-04-28T20:12:00+09:00 Subject: list local_variables in a def by means of a method Hello, As I work with ruby in combination with a programs API , i'm not able to use a debugger. (at least I think ::) So i'm looking for a way to list my variables. This is what I have: def listvar instance_variables.each {|inst| puts "#{inst} is #{inst.class} and is equal to #{eval(inst).inspect}" } local_variables.each {|var| puts "#{var} is #{var.class} and is equal to #{eval(var).inspect}" } end module Test @foo = 'good' def self.one foo = 'good' foo1 = 'better' foo2 = 'somehing' @foo.upcase! listvar end def self.two foo = 1 foo1 = 2 foo2 = 3 @foo.reverse! listvar end end Test.one ==> @foo is String and is equal to "GOOD" Test.two ==> @foo is String and is equal to "DOOG" So it works for instance_variables only, not for local_variables. If I want to list the local variables for self.one I have to do it like this: def self.one foo = 'good' foo1 = 'better' foo2 = 'somehing' @foo.upcase! local_variables.each {|var| puts "#{var} is #{var.class} and is equal to #{eval(var).inspect}" } end ==> foo is String and is equal to 1 foo1 is String and is equal to 2 foo2 is String and is equal to 3 But its not nice!!!!! How can i achieve this by just typing a command, like with the instance_variables?? Thnx Liquid -- Posted via http://www.ruby-forum.com/.