Sha256: bf0f9321eb384f13f704eb86d47c0c0a56debda89fd0e40d1e134dc309d2aac9
Contents?: true
Size: 271 Bytes
Versions: 10
Compression:
Stored size: 271 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] # def uniq_by #:yield: h = {}; inject([]) {|a,x| h[yield(x)] ||= a << x} end end
Version data entries
10 entries across 10 versions & 1 rubygems