Created
February 1, 2021 22:45
-
-
Save srcrip/8c50eb1556ae8809f379eb3e17aca1f1 to your computer and use it in GitHub Desktop.
Pointless method for turning arrays into hashes based on their positional index
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
# Converts an array like: | |
# ["M", nil, "G", nil, "G"] | |
# to: | |
# {0=>"M", 1=>nil, 2=>"G", 3=>nil, 4=>"G"} | |
def to_indexed_hash(arr) | |
arr.each_with_object({}).with_index { |(el, acc), index| acc[index] = el } | |
end | |
# Is this pointless? Probably. I thought it was interesting though. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment