Class: Dentaku::AST::Xor
- Defined in:
- lib/dentaku/ast/functions/xor.rb
Constant Summary
Constants inherited from Function
Instance Attribute Summary
Attributes inherited from Function
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Function
#accept, #dependencies, get, #initialize, numeric, register, register_class, registry
Methods inherited from Node
arity, #dependencies, #name, precedence, resolve_class, #type
Constructor Details
This class inherits a constructor from Dentaku::AST::Function
Class Method Details
.max_param_count ⇒ Object
11 12 13 |
# File 'lib/dentaku/ast/functions/xor.rb', line 11 def self.max_param_count Float::INFINITY end |
.min_param_count ⇒ Object
7 8 9 |
# File 'lib/dentaku/ast/functions/xor.rb', line 7 def self.min_param_count 1 end |
Instance Method Details
#value(context = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dentaku/ast/functions/xor.rb', line 15 def value(context = {}) if @args.empty? raise Dentaku::ArgumentError.for( :too_few_arguments, function_name: 'XOR()', at_least: 1, given: 0 ), 'XOR() requires at least one argument' end true_arg_count = 0 @args.each do |arg| case arg.value(context) when TrueClass true_arg_count += 1 break if true_arg_count > 1 when FalseClass, nil next else raise Dentaku::ArgumentError.for( :incompatible_type, function_name: 'XOR()', expect: :logical, actual: arg.class ), 'XOR() requires arguments to be logical expressions' end end true_arg_count == 1 end |