Sha256: febeadc75327c7aa0ece5746b318e477f048eb85938bc399ae5bb9e4ebf89a12

Contents?: true

Size: 644 Bytes

Versions: 7

Compression:

Stored size: 644 Bytes

Contents

require 'gorillib/object/blank'

class Hash
  #
  # remove all key-value pairs where the value is nil
  #
  def compact
    reject{|key,val| val.nil? }
  end unless method_defined?(:compact)

  #
  # Replace the hash with its compacted self
  #
  def compact!
    replace(compact)
  end unless method_defined?(:compact!)

  #
  # remove all key-value pairs where the value is blank
  #
  def compact_blank
    reject{|key,val| val.blank? }
  end unless method_defined?(:compact_blank)

  #
  # Replace the hash with its compact_blank'ed self
  #
  def compact_blank!
    replace(compact_blank)
  end unless method_defined?(:compact_blank!)
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gorillib-0.0.8 lib/gorillib/hash/compact.rb
gorillib-0.0.7 lib/gorillib/hash/compact.rb
gorillib-0.0.6 lib/gorillib/hash/compact.rb
gorillib-0.0.5 lib/gorillib/hash/compact.rb
gorillib-0.0.4 lib/gorillib/hash/compact.rb
gorillib-0.0.3 lib/gorillib/hash/compact.rb
gorillib-0.0.2 lib/gorillib/hash/compact.rb