Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/automation_helpers/extensions/array.rb
Overview
Additional useful methods to extend the Array class with
Class Method Summary collapse
-
.alphabet(type = :upper) ⇒ Array
Generates an array of the english alphabet Accepts an input to determine what case of alphabet you want.
Instance Method Summary collapse
-
#non_uniq ⇒ Array
Return the non-unique items of an array.
-
#uniq? ⇒ Boolean
Test whether an array is wholly unique.
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
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_uniq ⇒ Array
Return the non-unique items of an array
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
28 29 30 |
# File 'lib/automation_helpers/extensions/array.rb', line 28 def uniq? uniq == self end |