class Stannum::Constraints::Identity
An Identity
constraint checks for the exact object given.
@example Using an Identity
constraint
string = 'Greetings, programs!' constraint = Stannum::Constraints::Identity.new(string) constraint.matches?(nil) #=> false constraint.matches?('a string') #=> false constraint.matches?(string.dup) #=> false constraint.matches?(string) #=> true
Constants
- NEGATED_TYPE
The :type of the error generated for a matching object.
- TYPE
The :type of the error generated for a non-matching object.
Attributes
expected_value[R]
@return [Object] the expected object.
Public Class Methods
new(expected_value, **options)
click to toggle source
@param expected_value
[Object] The expected object. @param options [Hash<Symbol, Object>] Configuration options for the
constraint. Defaults to an empty Hash.
Calls superclass method
Stannum::Constraints::Base::new
# File lib/stannum/constraints/identity.rb, line 26 def initialize(expected_value, **options) @expected_value = expected_value super(expected_value: expected_value, **options) end
Public Instance Methods
matches?(actual)
click to toggle source
Checks that the object is the expected value.
@return [true, false] true if the object is the expected value, otherwise
false.
@see Stannum::Constraint#matches?
# File lib/stannum/constraints/identity.rb, line 41 def matches?(actual) expected_value.equal?(actual) end
Also aliased as: match?