Skip to content

Instantly share code, notes, and snippets.

@jaredcwhite
Created January 7, 2021 01:34
Show Gist options
  • Save jaredcwhite/14ce22fb449ccb78dc0998ea4cd5f3cd to your computer and use it in GitHub Desktop.
Save jaredcwhite/14ce22fb449ccb78dc0998ea4cd5f3cd to your computer and use it in GitHub Desktop.
Get a hash where key names match local variable values
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