class Stannum::Constraints::Absence
An absence constraint asserts that the object is nil or empty.
@example Using an Absence
constraint
constraint = Stannum::Constraints::Absence.new constraint.matches?(nil) #=> true constraint.matches?(Object.new) #=> false
@example Using a Absence
constraint with an Array
constraint.matches?([]) #=> true constraint.matches?([1, 2, 3]) #=> false
@example Using a Absence
constraint with an Hash
constraint.matches?({}) #=> true constraint.matches?({ key: 'value' }) #=> false
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.
Public Instance Methods
matches?(actual)
click to toggle source
Checks that the object is nil or empty.
@return [true, false] true if the object is nil or empty, otherwise false.
@see Stannum::Constraint#matches?
# File lib/stannum/constraints/absence.rb, line 33 def matches?(actual) return true if actual.nil? return true if actual.respond_to?(:empty?) && actual.empty? false end
Also aliased as: match?