Sha256: 80fc36e8bceb58f96c71085adbcc67e096a740de5623f9f3ed6cd9497bc57910

Contents?: true

Size: 572 Bytes

Versions: 7

Compression:

Stored size: 572 Bytes

Contents

# frozen_string_literal: true

class Hash
  def skip_nil_values
    dup.compact.each_with_object({}) do |(k, v), acc|
      next unless v
      acc[k] = case v
               when Hash
                 v.skip_nil_values
               when Array
                 v.compact
               else
                 v
               end
    end
  end

  def stringify_values
    self.deep_merge(self) do |_, _, v|
      if v.kind_of?(Hash)
        v.stringify_values
      elsif v.kind_of?(Array)
        v.stringify_values
      else
        v.to_s
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
remocon-0.4.2 lib/remocon/util/hash.rb
remocon-0.4.1 lib/remocon/util/hash.rb
remocon-0.4.0 lib/remocon/util/hash.rb
remocon-0.4.0.pre.1 lib/remocon/util/hash.rb
remocon-0.3.1 lib/remocon/util/hash.rb
remocon-0.3.0 lib/remocon/util/hash.rb
remocon-0.2.0 lib/remocon/util/hash.rb