Project

General

Profile

Actions

Feature #11087

closed

Method to retrieve {local,global,instance} variables as a Hash

Added by chancancode (Godfrey Chan) over 9 years ago. Updated over 9 years ago.

Status:
Feedback
Target version:
-
[ruby-core:68963]

Description

Rails implemented Object#instance_values which returns all the instance variables as a hash.

This is used for serialization, but it is pretty useful for introspection, debugging and reporting as well. (For example, it could be used to implement something like this.)

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?)
Actions

Also available in: Atom PDF

Like0
Like0Like0