From: Clemens Hintze Date: 2000-12-04T20:40:01+09:00 Subject: [ruby-talk:6798] Dump locals during debugging (was: Re: using join()) >>>>> "Joseph" == Joseph McDonald writes: (...) Joseph> Here's a prob I just tumbled into. During debugging it Joseph> would be cool to do something like: (...) Joseph> but I can't seem to get the objects name. Sorry to be pedantic here, but there are no object names in Ruby. Every variable is merely a place where a reference to a certain object is stored. That place is named in your code with a variable name. Strictly spoken, the Ruby compiler would be free to discard every variable name after compilation of your code if not necessary for debugging purposes. It looks more like: +- text -+ +-------+ | -+-------------> | world | +--------+ +-------+ Where the "world" is an instance of class String. You see, objects doesn't have names! But I often use following extension during debugging: class Binding def info_locals(*args) vars = eval("local_variables", self) vars &= args unless args.empty? vars.each { |v| puts %(#{v} --> #{eval(v, self).inspect}) } end end After 'require'ing I can use it as following: a = 12 b = 14 o = Object.new class Foo def initialize @v = 24 end end f = Foo.new urls = ["hello", "world"] text = "world!" puts "All:" binding.info_locals puts "\nOnly selected ones:" binding.info_locals "urls", "text" and get then: All: a --> 12 b --> 14 o --> # f --> # urls --> ["hello", "world"] text --> "world!" Only selected ones: urls --> ["hello", "world"] text --> "world!" HTH, \cle