Class: Matchi::Eq
- Inherits:
-
Object
- Object
- Matchi::Eq
- Defined in:
- lib/matchi/eq.rb
Overview
Value equivalence matcher that checks if two objects have identical values.
This matcher verifies value equality using Ruby’s Object#eql? method, which compares the values of objects rather than their identity. This is different from identity comparison (equal?) which checks if objects are the same instance.
Instance Method Summary collapse
-
#initialize(expected) ⇒ Eq
constructor
Initialize the matcher with a reference value.
-
#match? { ... } ⇒ Boolean
Checks if the yielded object has a value equivalent to the expected object.
-
#to_s ⇒ String
Returns a human-readable description of the matcher.
Constructor Details
#initialize(expected) ⇒ Eq
Initialize the matcher with a reference value.
44 45 46 |
# File 'lib/matchi/eq.rb', line 44 def initialize(expected) @expected = expected end |
Instance Method Details
#match? { ... } ⇒ Boolean
Checks if the yielded object has a value equivalent to the expected object.
This method uses Ruby’s Object#eql? method, which performs value comparison. Two objects are considered equivalent if they have the same value, even if they are different instances.
67 68 69 70 71 |
# File 'lib/matchi/eq.rb', line 67 def match? raise ::ArgumentError, "a block must be provided" unless block_given? @expected.eql?(yield) end |
#to_s ⇒ String
Returns a human-readable description of the matcher.
81 82 83 |
# File 'lib/matchi/eq.rb', line 81 def to_s "eq #{@expected.inspect}" end |