Module: Doing::ArrayCleanup
- Defined in:
- lib/doing/array/cleanup.rb
Instance Method Summary collapse
-
#remove_bad ⇒ Array
Like Array#compact -- removes nil items, but also removes empty strings, zero or negative numbers and FalseClass items.
- #remove_bad! ⇒ Object
-
#remove_empty ⇒ Array
Like Array#compact -- removes nil items, but also removes empty elements.
- #remove_empty! ⇒ Object
Instance Method Details
#remove_bad ⇒ Array
Like Array#compact -- removes nil items, but also removes empty strings, zero or negative numbers and FalseClass items
9 10 11 |
# File 'lib/doing/array/cleanup.rb', line 9 def remove_bad compact.map { |x| x.is_a?(String) ? x.strip : x }.select(&:good?) end |
#remove_bad! ⇒ Object
13 14 15 |
# File 'lib/doing/array/cleanup.rb', line 13 def remove_bad! replace remove_empty end |
#remove_empty ⇒ Array
Like Array#compact -- removes nil items, but also removes empty elements
23 24 25 |
# File 'lib/doing/array/cleanup.rb', line 23 def remove_empty compact.map { |x| x.is_a?(String) ? x.strip : x }.reject { |x| x.is_a?(String) ? x.empty? : false } end |
#remove_empty! ⇒ Object
27 28 29 |
# File 'lib/doing/array/cleanup.rb', line 27 def remove_empty! replace remove_empty end |