Class: RR::WildcardMatchers::HashIncluding
- Inherits:
-
Object
- Object
- RR::WildcardMatchers::HashIncluding
- Defined in:
- lib/rr/wildcard_matchers/hash_including.rb
Instance Attribute Summary collapse
-
#expected_hash ⇒ Object
readonly
Returns the value of attribute expected_hash.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(expected_hash) ⇒ HashIncluding
constructor
A new instance of HashIncluding.
- #inspect ⇒ Object
- #wildcard_match?(other) ⇒ Boolean
Constructor Details
#initialize(expected_hash) ⇒ HashIncluding
Returns a new instance of HashIncluding.
6 7 8 |
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 6 def initialize(expected_hash) @expected_hash = expected_hash.clone end |
Instance Attribute Details
#expected_hash ⇒ Object (readonly)
Returns the value of attribute expected_hash.
4 5 6 |
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 4 def expected_hash @expected_hash end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
22 23 24 25 |
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 22 def ==(other) return false unless other.is_a?(self.class) self.expected_hash == other.expected_hash end |
#inspect ⇒ Object
18 19 20 |
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 18 def inspect "hash_including(#{expected_hash.inspect})" end |
#wildcard_match?(other) ⇒ Boolean
10 11 12 13 14 15 16 |
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 10 def wildcard_match?(other) return true if self == other expected_hash.each_pair do |key, value| return false unless other.has_key?(key) && other[key] == expected_hash[key] end return true end |