Is there a way to access everything in the symbol table in Ruby? I want to be able to serialize or otherwise save the current state of a run of a program. To do this, it seems I need to be able to iterate over all the variables in scope.
+1
A:
If I have understood your question properly - that you would like to see all the symbols in your program then the following should do the trick:
puts Symbol.all_symbols.inspect
The “all_symbols” class method will return an Array of every Symbol currently in the program.
andHapp
2009-02-02 17:26:22
Be careful: you have to initialize my_array outside the loop, and as a result it will be included when you iterate over local_variables. You should add "unless var == 'my_array'" just before the closing curly brace to ignore it.
Bkkbrad
2009-02-02 23:53:32
Of course. I was only showing snippets .
Geo
2009-02-03 12:39:32