Sha256: 83231db9a1a502bb3b7466af873e862a3d7def265ba7dde56ac33f995f10673a

Contents?: true

Size: 566 Bytes

Versions: 1

Compression:

Stored size: 566 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.is_a?(Hash)
        v.stringify_values
      elsif v.is_a?(Array)
        v.stringify_values
      else
        v.to_s
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
remocon-0.1.0 lib/remocon/util/hash.rb