Class: Dry::Logic::Operations::And
- Defined in:
- lib/dry/logic/operations/and.rb
Instance Attribute Summary collapse
-
#hints ⇒ Object
readonly
Returns the value of attribute hints.
Attributes inherited from Binary
Attributes inherited from Abstract
Instance Method Summary collapse
- #[](input) ⇒ Object
- #call(input) ⇒ Object
-
#initialize ⇒ And
constructor
A new instance of And.
- #type ⇒ Object (also: #operator)
Methods inherited from Binary
Methods inherited from Abstract
#curry, #id, #new, #to_ast, #with
Methods included from Dry::Logic::Operators
Constructor Details
#initialize ⇒ And
Returns a new instance of And.
12 13 14 15 |
# File 'lib/dry/logic/operations/and.rb', line 12 def initialize(*) super @hints = .fetch(:hints, true) end |
Instance Attribute Details
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
10 11 12 |
# File 'lib/dry/logic/operations/and.rb', line 10 def hints @hints end |
Instance Method Details
#[](input) ⇒ Object
41 42 43 |
# File 'lib/dry/logic/operations/and.rb', line 41 def [](input) left[input] && right[input] end |
#call(input) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dry/logic/operations/and.rb', line 22 def call(input) left_result = left.(input) if left_result.success? right_result = right.(input) if right_result.success? Result::SUCCESS else Result.new(false, id) { right_result.ast(input) } end else Result.new(false, id) do left_ast = left_result.to_ast hints ? [type, [left_ast, [:hint, right.ast(input)]]] : left_ast end end end |
#type ⇒ Object Also known as: operator
17 18 19 |
# File 'lib/dry/logic/operations/and.rb', line 17 def type :and end |