B
Belorion
I have an array of arrays. I want to be able to do a uniq operation
on my array, and have it accept a block so I can specify what to
examine for uniqueness. For example, in IRB
a = [ [1,2], [3,4], [1,3] ]
a.sort { |x,y| x[0] <=> y[0] }
returns => [ [1,2], [1,3], [3,4] ]
However, it does not appear uniq accepts blocks:
a = [ [1,2], [3,4], [1,3] ]
a.uniq { |x,y| x[0] == y[0] }
returns => [ [1,2], [3,4], [1,3] ]
and a.uniq! with the above block returns nil.
Am I stuck writing my own deep_uniq? Granted, it would be hard, but
certainly not as clean as the above.
on my array, and have it accept a block so I can specify what to
examine for uniqueness. For example, in IRB
a = [ [1,2], [3,4], [1,3] ]
a.sort { |x,y| x[0] <=> y[0] }
returns => [ [1,2], [1,3], [3,4] ]
However, it does not appear uniq accepts blocks:
a = [ [1,2], [3,4], [1,3] ]
a.uniq { |x,y| x[0] == y[0] }
returns => [ [1,2], [3,4], [1,3] ]
and a.uniq! with the above block returns nil.
Am I stuck writing my own deep_uniq? Granted, it would be hard, but
certainly not as clean as the above.