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

Version Path
doing-2.1.88 lib/doing/array/cleanup.rb
doing-2.1.87 lib/doing/array/cleanup.rb
doing-2.1.86 lib/doing/array/cleanup.rb
doing-2.1.85 lib/doing/array/cleanup.rb
doing-2.1.84 lib/doing/array/cleanup.rb
doing-2.1.83 lib/doing/array/cleanup.rb
doing-2.1.82 lib/doing/array/cleanup.rb
doing-2.1.81 lib/doing/array/cleanup.rb
doing-2.1.80 lib/doing/array/cleanup.rb
doing-2.1.79 lib/doing/array/cleanup.rb
doing-2.1.78 lib/doing/array/cleanup.rb
doing-2.1.77 lib/doing/array/cleanup.rb
doing-2.1.76 lib/doing/array/cleanup.rb
doing-2.1.75 lib/doing/array/cleanup.rb
doing-2.1.74 lib/doing/array/cleanup.rb
doing-2.1.73 lib/doing/array/cleanup.rb
doing-2.1.72 lib/doing/array/cleanup.rb
doing-2.1.69 lib/doing/array/cleanup.rb
doing-2.1.68 lib/doing/array/cleanup.rb
doing-2.1.66 lib/doing/array/cleanup.rb