Sha256: 1644b5cde48478aa27add1f4727e1dd69bc027ba9721ea0312b7330ca90de4d4
Contents?: true
Size: 1.12 KB
Versions: 2
Compression:
Stored size: 1.12 KB
Contents
class Hash def wildcard_match?(other) return false unless other.is_a?(Hash) return false if size != other.size wildcards, exacts = partition {|key, _| key.respond_to?(:wildcard_match?)} other = other.dup exacts.each do |key, value| return false unless other.key?(key) other_value = other.delete(key) if value.respond_to?(:wildcard_match?) return false unless value.wildcard_match?(other_value) else return false unless value == other_value end end # TODO: Add support for the following case: # { # is_a(Symbol) => anything, # is_a(Symbol) => 1, # }.wildcard_match?(d: 1, c: 3) wildcards.each do |key, value| found = false other.each do |other_key, other_value| next unless key.wildcard_match?(other_key) if value.respond_to?(:wildcard_match?) next unless value.wildcard_match?(other_value) else next unless value == other_value end other.delete(other_key) found = true break end return false unless found end true end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rr-3.1.1 | lib/rr/core_ext/hash.rb |
rr-3.1.0 | lib/rr/core_ext/hash.rb |