module Doing::ArrayCleanup

Public Instance Methods

remove_bad() click to toggle source

Like Array#compact – removes nil items, but also removes empty strings, zero or negative numbers and FalseClass items

@return [Array] Array without “bad” elements

# 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!() click to toggle source
# File lib/doing/array/cleanup.rb, line 13
def remove_bad!
  replace remove_empty
end
remove_empty() click to toggle source

Like Array#compact – removes nil items, but also removes empty elements

@return [Array] Array without empty elements

# 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!() click to toggle source
# File lib/doing/array/cleanup.rb, line 27
def remove_empty!
  replace remove_empty
end