Class: Dry::Logic::Operations::Binary

Inherits:
Abstract
  • Object
show all
Defined in:
lib/dry/logic/operations/binary.rb

Direct Known Subclasses

And, Implication, Or, Xor

Instance Attribute Summary collapse

Attributes inherited from Abstract

#options, #rules

Instance Method Summary collapse

Methods inherited from Abstract

#curry, #id, #new, #to_ast, #with

Methods included from Dry::Logic::Operators

#and, #or, #then, #xor

Constructor Details

#initialize(*rules, **options) ⇒ Binary

Returns a new instance of Binary.



13
14
15
16
# File 'lib/dry/logic/operations/binary.rb', line 13

def initialize(*rules, **options)
  super
  @left, @right = rules
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



9
10
11
# File 'lib/dry/logic/operations/binary.rb', line 9

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



11
12
13
# File 'lib/dry/logic/operations/binary.rb', line 11

def right
  @right
end

Instance Method Details

#ast(input = Undefined) ⇒ Object



18
19
20
# File 'lib/dry/logic/operations/binary.rb', line 18

def ast(input = Undefined)
  [type, [left.ast(input), right.ast(input)]]
end

#to_sObject



22
23
24
# File 'lib/dry/logic/operations/binary.rb', line 22

def to_s
  "#{left} #{operator.to_s.upcase} #{right}"
end