Created
July 15, 2020 03:43
-
-
Save smtlaissezfaire/e81356c390ae7c7d38d435ead1ce58d2 to your computer and use it in GitHub Desktop.
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
$ irb -r './hash_shorthand.rb' | |
>> x = 10 | |
>> y = 20 | |
>> | |
>> puts hash_shorthand(binding, :x, :y) | |
{:x=>10, :y=>20} |
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
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