Class: Dentaku::AST::RubyMath
Constant Summary
collapse
- ARRAY_RETURN_TYPES =
[:frexp, :lgamma].freeze
Constants inherited
from Function
Function::DIG
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Function
#deferred_args, #dependencies, get, #initialize, numeric, register, register_class, registry
Methods inherited from Node
#dependencies, peek, precedence
Class Method Details
.[](method) ⇒ Object
7
8
9
10
11
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 7
def self.[](method)
klass = Class.new(self)
klass.implement(method)
klass
end
|
.arity ⇒ Object
22
23
24
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 22
def self.arity
@implementation.arity < 0 ? nil : @implementation.arity
end
|
.call(*args) ⇒ Object
34
35
36
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 34
def self.call(*args)
@implementation.call(*args)
end
|
.implement(method) ⇒ Object
13
14
15
16
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 13
def self.implement(method)
@name = method
@implementation = Math.method(method)
end
|
.max_param_count ⇒ Object
30
31
32
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 30
def self.max_param_count
@implementation.parameters.select { |type, _name| type == :rest }.any? ? Float::INFINITY : @implementation.parameters.count
end
|
.min_param_count ⇒ Object
26
27
28
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 26
def self.min_param_count
@implementation.parameters.select { |type, _name| type == :req }.count
end
|
.name ⇒ Object
18
19
20
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 18
def self.name
@name
end
|
Instance Method Details
#type ⇒ Object
45
46
47
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 45
def type
ARRAY_RETURN_TYPES.include?(@name) ? :array : :numeric
end
|
#value(context = {}) ⇒ Object
38
39
40
41
|
# File 'lib/dentaku/ast/functions/ruby_math.rb', line 38
def value(context = {})
args = @args.flatten.map { |a| Dentaku::AST::Function.numeric(a.value(context)) }
self.class.call(*args)
end
|