Skip to content

Instantly share code, notes, and snippets.

@leastbad
Created November 10, 2022 08:36
Show Gist options
  • Select an option

  • Save leastbad/31c4a94501df2698b89628dffa6ac269 to your computer and use it in GitHub Desktop.

Select an option

Save leastbad/31c4a94501df2698b89628dffa6ac269 to your computer and use it in GitHub Desktop.

Revisions

  1. leastbad created this gist Nov 10, 2022.
    11 changes: 11 additions & 0 deletions indexable_by_hash_patch.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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])