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
11 12 13 |
# File 'lib/doing/array/cleanup.rb', line 11 def remove_bad compact.map { |x| x.is_a?(String) ? x.strip : x }.select(&:good?) end |
#remove_bad! ⇒ Object
15 16 17 |
# File 'lib/doing/array/cleanup.rb', line 15 def remove_bad! replace remove_empty end |
#remove_empty ⇒ Array
Like Array#compact -- removes nil items, but also removes empty elements
25 26 27 |
# File 'lib/doing/array/cleanup.rb', line 25 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
29 30 31 |
# File 'lib/doing/array/cleanup.rb', line 29 def remove_empty! replace remove_empty end |