# Make an array of hashes contain a unique value for key: def uniquify_array(array, key) array.group_by { |item| item[key] }.map do |_, items| (items.length > 1) ? yield(items) : items.first end end # new_array = uniquify_array(array, :some_key) do |dupes| # dupes.max_by { |item| item[:updated_at] } # end # @PICOPACKAGE_START # --- # filename: uniquify_array.rb # url: https://api.github.com/gists/525ac4177964549ee2f2ca7febd03eea # version: 0.1 # source_url: https://gist.github.com/dkam/525ac4177964549ee2f2ca7febd03eea # @PICOPACKAGE_END