Module: MoreCoreExtensions::ArrayDeletes
- Defined in:
- lib/more_core_extensions/core_ext/array/deletes.rb
Instance Method Summary collapse
-
#deep_delete(key) ⇒ Object
Deletes all keys and subkeys that match
key
. -
#delete_blanks ⇒ Object
Deletes all items where the value is blank.
-
#delete_nils ⇒ Object
Deletes all items where the value is nil.
Instance Method Details
#deep_delete(key) ⇒ Object
Deletes all keys and subkeys that match key
.
[{:a => {:b => 2, :c => 3}}].deep_delete(:b) # => [{:a => {:c => 3}}]
23 24 25 26 |
# File 'lib/more_core_extensions/core_ext/array/deletes.rb', line 23 def deep_delete(key) each { |i| i.deep_delete(key) if i.respond_to?(:deep_delete) } self end |
#delete_blanks ⇒ Object
Deletes all items where the value is blank
[1, [], nil].delete_blanks # => [1]
15 16 17 |
# File 'lib/more_core_extensions/core_ext/array/deletes.rb', line 15 def delete_blanks delete_if { |i| i.blank? } end |
#delete_nils ⇒ Object
Deletes all items where the value is nil
[1, [], nil].delete_nils # => [1, []]
8 9 10 |
# File 'lib/more_core_extensions/core_ext/array/deletes.rb', line 8 def delete_nils delete_if { |i| i.nil? } end |