Skip to content

Instantly share code, notes, and snippets.

@vakiliy
Last active December 31, 2015 11:19
Show Gist options
  • Save vakiliy/45bfd14924aefa101f1a to your computer and use it in GitHub Desktop.
Save vakiliy/45bfd14924aefa101f1a to your computer and use it in GitHub Desktop.
Get variable name
string = 'Just String'
type = defined?(string)
list = {
"local-variable" => local_variables,
"instance-variable" => instance_variables,
"global-variable" => global_variables
}[type] || []
name = list.find {|v| eval(v.to_s) == string}
puts name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment