Module: Dry::Logic::Builder

Defined in:
lib/dry/logic/builder.rb

Defined Under Namespace

Classes: Context

Constant Summary collapse

IGNORED_OPERATIONS =
%i[
  Abstract
  Binary
  Unary
].freeze
IGNORED_PREDICATES =
[
  :predicate
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(&context) ⇒ Builder::Result

Predicate and operation builder

Examples:

Check if input is zero

is_zero = Dry::Logic::Builder.call do
  negation { lt?(0) ^ gt?(0) }
end

p is_zero.call(1) # => false
p is_zero.call(0) # => true
p is_zero.call(-1) # => false

Returns:

  • (Builder::Result)


31
32
33
# File 'lib/dry/logic/builder.rb', line 31

def call(&context)
  Context.instance.call(&context)
end

Instance Method Details

#call(&context) ⇒ Builder::Result Also known as: build

Predicate and operation builder

Examples:

Check if input is zero

is_zero = Dry::Logic::Builder.call do
  negation { lt?(0) ^ gt?(0) }
end

p is_zero.call(1) # => false
p is_zero.call(0) # => true
p is_zero.call(-1) # => false

Returns:

  • (Builder::Result)


31
32
33
# File 'lib/dry/logic/builder.rb', line 31

def call(&context)
  Context.instance.call(&context)
end