Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/automation_helpers/extensions/array.rb

Overview

Additional useful methods to extend the Array class with

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.alphabet(type = :upper) ⇒ Array

Generates an array of the english alphabet Accepts an input to determine what case of alphabet you want

Returns:



9
10
11
12
13
14
15
16
# File 'lib/automation_helpers/extensions/array.rb', line 9

def self.alphabet(type = :upper)
  case type
  when :upper; then ('A'..'Z').to_a
  when :lower; then ('a'..'z').to_a
  when :both;  then ('a'..'z').to_a + ('A'..'Z').to_a
  else raise ArgumentError, 'Invalid alphabet type. Must be :upper (default), :lower or :both'
  end
end

Instance Method Details

#non_uniqArray

Return the non-unique items of an array

Returns:



21
22
23
# File 'lib/automation_helpers/extensions/array.rb', line 21

def non_uniq
  tally.select { |_key, count| count > 1 }.map(&:first)
end

#uniq?Boolean

Test whether an array is wholly unique

Returns:

  • (Boolean)


28
29
30
# File 'lib/automation_helpers/extensions/array.rb', line 28

def uniq?
  uniq == self
end