Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/modern/core_ext/array.rb

Instance Method Summary collapse

Instance Method Details

#deep_compact!Object



14
15
16
17
18
19
20
21
22
# File 'lib/modern/core_ext/array.rb', line 14

def deep_compact!
  each do |v|
    if v.is_a?(Hash) || v.respond_to?(:values)
      v.values.deep_compact!
    elsif v.is_a?(Array) || v.respond_to?(:each)
      v.deep_compact!
    end
  end
end

#duplicatesObject



10
11
12
# File 'lib/modern/core_ext/array.rb', line 10

def duplicates
  group_by(&:itself).map { |e| e[0] if e[1][1] }.compact
end

#subsequencesObject



4
5
6
7
8
# File 'lib/modern/core_ext/array.rb', line 4

def subsequences
  (0..length).map do |n|
    self[0, n]
  end
end