Method: Immutable::Vector#uniq
- Defined in:
- lib/immutable/vector.rb
#uniq(&block) ⇒ Vector
Return a new Vector with no duplicate elements, as determined by #hash and #eql?. For each group of equivalent elements, only the first will be retained.
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'lib/immutable/vector.rb', line 537 def uniq(&block) array = self.to_a if block_given? if array.frozen? self.class.new(array.uniq(&block).freeze) elsif array.uniq!(&block) # returns nil if no changes were made self.class.new(array.freeze) else self end elsif array.frozen? self.class.new(array.uniq.freeze) elsif array.uniq! # returns nil if no changes were made self.class.new(array.freeze) else self end end |