Created
November 10, 2022 08:36
-
-
Save leastbad/31c4a94501df2698b89628dffa6ac269 to your computer and use it in GitHub Desktop.
Array to_proc
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
module IndexableByHashPatch | |
refine Array do | |
def to_proc | |
->(h) { length == 1 ? h[first] : h.values_at(*self) } | |
end | |
end | |
end | |
using IndexableByHashPatch | |
indexed_records = json.index_by(&[:item_type, :item_id]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit to @ni3t