Sha256: 2c1851bd1f50d2a5ff9d42ce005c3944fd312ce5ca4e3f250563a43bed0861e7

Contents?: true

Size: 635 Bytes

Versions: 2

Compression:

Stored size: 635 Bytes

Contents

# frozen_string_literal: true

module Micro
  class Case
    module Utils
      def self.symbolize_hash_keys(hash)
        if Kind::Of::Hash(hash).respond_to?(:transform_keys)
          hash.transform_keys { |key| key.to_sym rescue key }
        else
          hash.each_with_object({}) do |(k, v), memo|
            key = k.to_sym rescue k

            memo[key] = v
          end
        end
      end

      def self.slice_hash(hash, keys)
        if Kind::Of::Hash(hash).respond_to?(:slice)
          hash.slice(*keys)
        else
          hash.select { |key, _value| keys.include?(key) }
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
u-case-4.0.0 lib/micro/case/utils.rb
u-case-3.1.0 lib/micro/case/utils.rb