Skip to content

Instantly share code, notes, and snippets.

@leastbad
Created November 10, 2022 08:36
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 leastbad/31c4a94501df2698b89628dffa6ac269 to your computer and use it in GitHub Desktop.
Save leastbad/31c4a94501df2698b89628dffa6ac269 to your computer and use it in GitHub Desktop.
Array to_proc
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])
@leastbad
Copy link
Author

Credit to @ni3t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment