Issue #11087 has been updated by Koichi Sasada.

Status changed from Open to Feedback

----------------------------------------
Feature #11087: Method to retrieve {local,global,instance} variables as a Hash
https://bugs.ruby-lang.org/issues/11087#change-52877

* Author: Godfrey Chan
* Status: Feedback
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
Rails implemented [Object#instance_values](http://api.rubyonrails.org/classes/Object.html#method-i-instance_values) which returns all the instance variables as a hash.

This is used for [serialization](https://github.com/rails/rails/blob/7c7d9dcf5a966a5490fe99230ab9513d73df9630/activesupport/lib/active_support/core_ext/object/json.rb#L52), but it is pretty useful for introspection, debugging and reporting as well. (For example, it could be used to implement [something like this](https://github.com/rails/web-console/issues/121#issuecomment-89956638).)

I was going to propose an equivalent for local variables (and I suppose global variables too, for completeness), but if there are interest maybe we can do this on Ruby instead.

There are also some open questions:

* Naming
* Hash or iterator? (like Rails' `Object#instance_value` or like `ObjectSpace.each_object`)
* Rails' `Object#instance_values` removes the leading `@`, are we going to do the same? (Probably not?)



-- 
https://bugs.ruby-lang.org/