Devon Parsons
Devon Parsons

Reputation: 1288

Mix debugger commands and ruby code evaluation

I'm currently upgrading an old project from and old version of ruby(1.8.7)/rails(3.0) to 1.9.3/3.1 (as a stepping stone to newer versions).

I'm using gems debugger for 1.9.3 and ruby-debug for 1.8.7

When I run , I can run commands like info variables to get the list and values of all currently-scoped variables:

...
@current_phone = nil
@fields = {}
@global = {:source_type=>"pdf"}
@images = []
@index = {}
@lines = []
...

Also I can run arbitrary ruby code - a useful one I've been using is

File.open("/tmp/new_version", "w"){|f|f.write(@fields)}

which is useful for me to quickly compare between the old version and the new version using a file diff program.

Can I link these together so I can write to a file all the output of info variables? It would be sufficient if I could do

tempvar = info variables

or something along those lines, of course, but that gives

*** NameError Exception: undefined local variable or method `variables' for <ClassWhatever>

Upvotes: 0

Views: 32

Answers (1)

iced
iced

Reputation: 1572

instance_variables.map { |v| [v, instance_variable_get(v)] }

Not exactly hash map, but you'll be good with it.

Upvotes: 1

Related Questions