Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/robot_array.rb

Instance Method Summary collapse

Instance Method Details

#dupes?Boolean

Returns true if this array has duplicates in it

["a", "b", "c", "a"].dupes?
# => true

Returns:

  • (Boolean)


7
8
9
# File 'lib/robot_array.rb', line 7

def dupes?
  self.uniq.length != self.length
end

#dupes_by?(&block) ⇒ Boolean

Returns true if this array has duplicates in it, using the test passed in for uniqueness rather than the built in ruby test for equality.

["a", "b", "c", "A"].dupes_by?(&:downcase)
# => true

Returns:

  • (Boolean)


18
19
20
# File 'lib/robot_array.rb', line 18

def dupes_by?(&block)
  self.uniq_by(&block).length != self.length
end