Class: Stannum::Constraints::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/stannum/constraints/boolean.rb

Overview

A Boolean constraint matches only true or false.

Examples:

Using a Boolean constraint

constraint = Stannum::Constraints::Boolean.new

constraint.matches?(nil)        #=> false
constraint.matches?('a string') #=> false
constraint.matches?(false)      #=> true
constraint.matches?(true)       #=> true

Constant Summary collapse

NEGATED_TYPE =

The :type of the error generated for a matching object.

'stannum.constraints.is_boolean'
TYPE =

The :type of the error generated for a non-matching object.

'stannum.constraints.is_not_boolean'

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#==, #clone, #does_not_match?, #dup, #errors_for, #initialize, #match, #message, #negated_errors_for, #negated_match, #negated_message, #negated_type, #type, #with_options

Constructor Details

This class inherits a constructor from Stannum::Constraints::Base

Instance Method Details

#matches?(actual) ⇒ true, false Also known as: match?

Checks that the object is either true or false.

Returns:

  • (true, false)

    true if the object is true or false, otherwise false.

See Also:



28
29
30
# File 'lib/stannum/constraints/boolean.rb', line 28

def matches?(actual)
  true.equal?(actual) || false.equal?(actual)
end