Sha256: 907ba604f5cb4f130cf723f67dcd9f11a3fdecf48097e5daba9d2b86d97199a2
Contents?: true
Size: 1.12 KB
Versions: 4
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true module Refinements # Refinements for hashes. module Hashes refine Hash do def except *keys reject { |key, _value| keys.include? key } end def except! *keys replace except(*keys) end def symbolize_keys dup.symbolize_keys! end def symbolize_keys! keys.each { |key| self[key.to_sym] = delete key } self end def deep_merge other dup.deep_merge! other end # :reek:FeatureEnvy def deep_merge! other merge! other do |_key, this_value, other_value| if this_value.is_a?(Hash) && other_value.is_a?(Hash) this_value.deep_merge other_value else other_value end end end def reverse_merge other other.merge self end def reverse_merge! other merge!(other) { |_key, old_value, _new_value| old_value } end def use &block return [] unless block_given? values = block.parameters.map { |(_type, key)| self[key] } yield values end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
refinements-6.2.1 | lib/refinements/hashes.rb |
refinements-6.2.0 | lib/refinements/hashes.rb |
refinements-6.1.0 | lib/refinements/hashes.rb |
refinements-6.0.0 | lib/refinements/hashes.rb |