Class: Array

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

Instance Method Summary collapse

Instance Method Details

#recursively_delete_keys!(*keys) ⇒ Object



2
3
4
# File 'lib/core_ext/array.rb', line 2

def recursively_delete_keys! *keys
  self.each { |v| v.recursively_delete_keys!(*keys) if v.is_a?(Hash) || v.is_a?(Array) } ; self
end

#recursively_remove_by_value!(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/core_ext/array.rb', line 18

def recursively_remove_by_value! &block
  self.delete_if { |v|
    if v.is_a? Hash
      v.recursively_remove_by_value! &block
      v.empty?
    elsif v.is_a? Array
      v.recursively_remove_by_value! &block
      v.empty?
    else
      yield v
    end
  }
end

#recursively_replace_keys!(&block) ⇒ Object



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

def recursively_replace_keys! &block
  self.each { |v| v.recursively_replace_keys!(&block) if v.is_a?(Hash) || v.is_a?(Array) } ; self
end

#recursively_replace_values(&block) ⇒ Object



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

def recursively_replace_values &block
  result = []
  each_with_index { |v, i|
    result << ((v.is_a?(Hash) || v.is_a?(Array)) ? v.recursively_replace_values(&block) : yield(i, v))
  }
  result
end