Skip to content

Instantly share code, notes, and snippets.

@aprescott
Created April 5, 2011 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprescott/903529 to your computer and use it in GitHub Desktop.
Save aprescott/903529 to your computer and use it in GitHub Desktop.
Finding local variable references within the current scope
>> local_variables
=> ["_"]
>> a = ""
=> ""
>> local_variables
=> ["_", "a"]
>> b = binding; local_variables.select { |var| b.eval(var).object_id == a.object_id }
=> ["a"]
>> x = a
=> ""
>> local_variables
=> ["_", "a", "b", "x"]
>> b = binding; local_variables.select { |var| b.eval(var).object_id == a.object_id }
=> ["a", "x"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment