Sha256: e6655a9efe68370db02ba534602363302dcfce28c7f67036dfb56cfbb05bc394

Contents?: true

Size: 644 Bytes

Versions: 3

Compression:

Stored size: 644 Bytes

Contents

require_relative '../function'
require_relative '../../exceptions'

Dentaku::AST::Function.register(:and, :logical, lambda { |*args|
  if args.empty?
    raise Dentaku::ArgumentError.for(
      :too_few_arguments,
      function_name: 'AND()', at_least: 1, given: 0
    ), 'AND() requires at least one argument'
  end

  args.all? do |arg|
    case arg
    when TrueClass, nil
      true
    when FalseClass
      false
    else
      raise Dentaku::ArgumentError.for(
        :incompatible_type,
        function_name: 'AND()', expect: :logical, actual: arg.class
      ), 'AND() requires arguments to be logical expressions'
    end
  end
})

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dentaku-3.2.0 lib/dentaku/ast/functions/and.rb
dentaku-3.1.0 lib/dentaku/ast/functions/and.rb
dentaku-3.0.0 lib/dentaku/ast/functions/and.rb