Sha256: 86fd6d983703430e4b1c39c0bacc4b0a55b65e226b482898030670d6c945bb97
Contents?: true
Size: 288 Bytes
Versions: 7
Compression:
Stored size: 288 Bytes
Contents
module Enumerable # Like #uniq, but determines uniqueness based on a given block. # # (-5..5).to_a.uniq_by {|i| i*i } # # produces # # [-5, -4, -3, -2, -1, 0] # # CREDIT: ? def uniq_by #:yield: h = {}; inject([]) {|a,x| h[yield(x)] ||= a << x} end end
Version data entries
7 entries across 7 versions & 2 rubygems