Module: DeeplyEnumerable::ArrayExtension
Class Method Summary collapse
Instance Method Summary collapse
-
#deep_compact ⇒ Object
Recursively removes nil elements, leaving every other element (including already-blank ones such as “”, [] and {}) untouched.
-
#deep_compact! ⇒ Object
In-place variant of #deep_compact, mirroring Array#compact!.
-
#deep_compact_blank ⇒ Object
Recursively removes every blank element (nil, false, “”, “ ”, [], {}).
-
#deep_compact_blank! ⇒ Object
In-place variant of #deep_compact_blank, mirroring Array#compact_blank!.
-
#deep_compact_blanked ⇒ Object
Recursively removes nils and collections that became blank through compaction, but keeps elements that were already blank.
-
#deep_compact_blanked! ⇒ Object
In-place variant of #deep_compact_blanked.
-
#deep_compact_existing_blank ⇒ Object
Recursively removes nils and elements that are already blank, but keeps collections that only become blank as a result of compaction.
-
#deep_compact_existing_blank! ⇒ Object
In-place variant of #deep_compact_existing_blank.
Class Method Details
.included(klass) ⇒ Object
5 6 7 8 9 |
# File 'lib/deeply_enumerable/array.rb', line 5 def self.included klass klass.class_eval do include DeeplyEnumerable::Enumerable end end |
Instance Method Details
#deep_compact ⇒ Object
Recursively removes nil elements, leaving every other element (including already-blank ones such as “”, [] and {}) untouched. This is the recursive counterpart of Ruby’s Array#compact. docs.ruby-lang.org/en/master/Array.html#method-i-compact
15 16 17 |
# File 'lib/deeply_enumerable/array.rb', line 15 def deep_compact deep_compact_each(false, false) end |
#deep_compact! ⇒ Object
In-place variant of #deep_compact, mirroring Array#compact!.
20 21 22 |
# File 'lib/deeply_enumerable/array.rb', line 20 def deep_compact! replace(deep_compact) end |
#deep_compact_blank ⇒ Object
Recursively removes every blank element (nil, false, “”, “ ”, [], {}). This is the recursive counterpart of Rails’ Array#compact_blank. github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/enumerable.rb
49 50 51 |
# File 'lib/deeply_enumerable/array.rb', line 49 def deep_compact_blank deep_compact_each(true, true) end |
#deep_compact_blank! ⇒ Object
In-place variant of #deep_compact_blank, mirroring Array#compact_blank!.
54 55 56 |
# File 'lib/deeply_enumerable/array.rb', line 54 def deep_compact_blank! replace(deep_compact_blank) end |
#deep_compact_blanked ⇒ Object
Recursively removes nils and collections that became blank through compaction, but keeps elements that were already blank.
37 38 39 |
# File 'lib/deeply_enumerable/array.rb', line 37 def deep_compact_blanked deep_compact_each(true, false) end |
#deep_compact_blanked! ⇒ Object
In-place variant of #deep_compact_blanked.
42 43 44 |
# File 'lib/deeply_enumerable/array.rb', line 42 def deep_compact_blanked! replace(deep_compact_blanked) end |
#deep_compact_existing_blank ⇒ Object
Recursively removes nils and elements that are already blank, but keeps collections that only become blank as a result of compaction.
26 27 28 |
# File 'lib/deeply_enumerable/array.rb', line 26 def deep_compact_existing_blank deep_compact_each(false, true) end |
#deep_compact_existing_blank! ⇒ Object
In-place variant of #deep_compact_existing_blank.
31 32 33 |
# File 'lib/deeply_enumerable/array.rb', line 31 def deep_compact_existing_blank! replace(deep_compact_existing_blank) end |