0

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>
2
  • What debugger are you using? Commented Mar 6, 2015 at 19:29
  • @Jordan Gem 'debugger' for 1.9.3 and 'ruby-debug' for 1.8.7 Commented Mar 6, 2015 at 19:42

1 Answer 1

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

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

Sign up to request clarification or add additional context in comments.

2 Comments

Show just instance_variables output
Ahh yes, you got arrays in some of your variables. Will fix answer now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.