Last active
December 31, 2015 11:19
-
-
Save vakiliy/45bfd14924aefa101f1a to your computer and use it in GitHub Desktop.
Get variable name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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