Sha256: 75cbe2d7a52d0504c065c5701e9cc60055c77823fe68ab49458c4f26a08eaf5c
Contents?: true
Size: 783 Bytes
Versions: 4
Compression:
Stored size: 783 Bytes
Contents
# frozen_string_literal: true module Micro::Case::Utils module Hashes def self.respond_to?(hash, method) Kind::Hash[hash].respond_to?(method) end def self.symbolize_keys(hash) return hash.transform_keys { |key| key.to_sym rescue key } if respond_to?(hash, :transform_keys) hash.each_with_object({}) do |(k, v), memo| key = k.to_sym rescue k memo[key] = v end end def self.stringify_keys(hash) return hash.transform_keys(&:to_s) if respond_to?(hash, :transform_keys) hash.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v } end def self.slice(hash, keys) return hash.slice(*keys) if respond_to?(hash, :slice) hash.select { |key, _value| keys.include?(key) } end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
u-case-4.5.1 | lib/micro/case/utils.rb |
u-case-4.5.0 | lib/micro/case/utils.rb |
u-case-4.4.0 | lib/micro/case/utils.rb |
u-case-4.3.0 | lib/micro/case/utils.rb |