class Dentaku::AST::RubyMath

Constants

ARRAY_RETURN_TYPES

Public Class Methods

[](method) click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 7
def self.[](method)
  klass_name = method.to_s.capitalize
  klass = const_set(klass_name , Class.new(self))
  klass.implement(method)
  const_get(klass_name)
end
arity() click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 23
def self.arity
  @implementation.arity < 0 ? nil : @implementation.arity
end
call(*args) click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 35
def self.call(*args)
  @implementation.call(*args)
rescue Math::DomainError => _e
  raise Dentaku::MathDomainError.new(name, args)
end
implement(method) click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 14
def self.implement(method)
  @name = method
  @implementation = Math.method(method)
end
max_param_count() click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 31
def self.max_param_count
  @implementation.parameters.select { |type, _name| type == :rest }.any? ? Float::INFINITY : @implementation.parameters.count
end
min_param_count() click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 27
def self.min_param_count
  @implementation.parameters.select { |type, _name| type == :req }.count
end
name() click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 19
def self.name
  @name
end

Public Instance Methods

type() click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 48
def type
  ARRAY_RETURN_TYPES.include?(@name) ? :array : :numeric
end
value(context = {}) click to toggle source
# File lib/dentaku/ast/functions/ruby_math.rb, line 41
def value(context = {})
  args = @args.flatten.map { |a| Dentaku::AST::Function.numeric(a.value(context)) }
  self.class.call(*args)
end