uniq

ary.uniq â new_ary
ary.uniq { |item| ... } â new_ary
Instance Public methods

Returns a new array by removing duplicate values in self.

If a block is given, it will use the return value of the block for comparison.

It compares values using their hash and eql? methods for efficiency.

a = [ "a", "a", "b", "b", "c" ]
a.uniq   # => ["a", "b", "c"]

b = [["student","sam"], ["student","george"], ["teacher","matz"]]
b.uniq { |s| s.first } # => [["student", "sam"], ["teacher", "matz"]]
doc_ruby_on_rails
2015-03-30 21:17:03
Comments
Leave a Comment

Please login to continue.