Sha256: 6d1d1c3e799e2fe7826e8083e603b76942cb08cfdf28d5a589fe63916a5bd334
Contents?: true
Size: 768 Bytes
Versions: 40
Compression:
Stored size: 768 Bytes
Contents
module Doing module ArrayCleanup ## ## Like Array#compact -- removes nil items, but also ## removes empty strings, zero or negative numbers and FalseClass items ## ## @return [Array] Array without "bad" elements ## def remove_bad compact.map { |x| x.is_a?(String) ? x.strip : x }.select(&:good?) end def remove_bad! replace remove_empty end ## ## Like Array#compact -- removes nil items, but also ## removes empty elements ## ## @return [Array] Array without empty elements ## def remove_empty compact.map { |x| x.is_a?(String) ? x.strip : x }.reject { |x| x.is_a?(String) ? x.empty? : false } end def remove_empty! replace remove_empty end end end
Version data entries
40 entries across 40 versions & 1 rubygems