File: hash.rb

package info (click to toggle)
ruby-rr 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,436 kB
  • ctags: 1,404
  • sloc: ruby: 11,657; makefile: 5
file content (22 lines) | stat: -rw-r--r-- 614 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Hash
  def wildcard_match?(other)
    return false unless other.is_a?(Hash)

    other_keys = other.keys
    return false if keys.size != other_keys.size

    other_values = other.values
    each_with_index do |(key, value), i|
      if key.respond_to?(:wildcard_match?)
        return false unless key.wildcard_match?(other_keys[i])
      else
        return false unless key == other_keys[i]
      end
      if value.respond_to?(:wildcard_match?)
        return false unless value.wildcard_match?(other_values[i])
      else
        return false unless value == other_values[i]
      end
    end
  end
end