Class: Flows::Contract::CaseEq
- Inherits:
-
Flows::Contract
- Object
- Flows::Contract
- Flows::Contract::CaseEq
- Defined in:
- lib/flows/contract/case_eq.rb
Overview
Makes a contract from provided object's case equality check.
Instance Method Summary collapse
- #check!(other) ⇒ Object
-
#initialize(object, error_message = nil) ⇒ CaseEq
constructor
A new instance of CaseEq.
Methods inherited from Flows::Contract
#===, #check, make, #to_proc, #transform, #transform!
Constructor Details
#initialize(object, error_message = nil) ⇒ CaseEq
Returns a new instance of CaseEq.
25 26 27 28 |
# File 'lib/flows/contract/case_eq.rb', line 25 def initialize(object, = nil) @object = object @error_message = end |
Instance Method Details
#check!(other) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/flows/contract/case_eq.rb', line 31 def check!(other) unless @object === other value_error = @error_message || "must match `#{@object.inspect}`, but has class `#{other.class.inspect}` and value `#{other.inspect}`" raise Error.new(other, value_error) end true end |