Last active
November 25, 2023 10:16
-
-
Save dskecse/c7e9fd3495b3126d061c08d074700816 to your computer and use it in GitHub Desktop.
Python dict magic to Ruby
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
matches = dict(['()', '[]', '{}']) | |
print(matches) | |
# {'(': ')', '[': ']', '{': '}'} |
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
Hash[['()'.split('')]] | |
# {"("=>")"} | |
['()'.split('')] | |
# [["(", ")"]] | |
Hash[ [["(", ")"], ["[", "]"]] ] | |
# {"("=>")", "["=>"]"} | |
['()', '[]', '{}'].map { _1.split('') } | |
# [["(", ")"], ["[", "]"], ["{", "}"]] | |
matches = Hash[['()', '[]', '{}'].map { _1.split('') }] | |
# {"("=>")", "["=>"]", "{"=>"}"} | |
matches = ['()', '[]', '{}'].map { _1.split('') }.to_h | |
# {"("=>")", "["=>"]", "{"=>"}"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment