Skip to content

Instantly share code, notes, and snippets.

@smtlaissezfaire
Created July 15, 2020 03:43
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 smtlaissezfaire/e81356c390ae7c7d38d435ead1ce58d2 to your computer and use it in GitHub Desktop.
Save smtlaissezfaire/e81356c390ae7c7d38d435ead1ce58d2 to your computer and use it in GitHub Desktop.
$ irb -r './hash_shorthand.rb'
>> x = 10
>> y = 20
>>
>> puts hash_shorthand(binding, :x, :y)
{:x=>10, :y=>20}
def hash_shorthand(source_binding, *symbols)
hash = {}
symbols.each do |symbol|
hash[symbol] = source_binding.local_variable_get(symbol)
end
hash
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment