Created
January 7, 2021 01:34
-
-
Save jaredcwhite/14ce22fb449ccb78dc0998ea4cd5f3cd to your computer and use it in GitHub Desktop.
Get a hash where key names match local variable values
This file contains hidden or 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
class Binding | |
def hash_for_locals(*keys) | |
values = {} | |
keys.each do |key| | |
values[key] = local_variable_get(key) | |
end | |
values | |
end | |
end | |
a = 123 | |
b = "xyz" | |
binding.hash_for_locals :a, :b | |
# {:a=>123, :b=>"xyz"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment