Class: Dentaku::AST::Function
- Inherits:
-
Node
- Object
- Node
- Dentaku::AST::Function
show all
- Defined in:
- lib/dentaku/ast/function.rb
Constant Summary
collapse
- DIG =
Returns with the number of significant decimal digits to use.
Float::DIG + 1
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Node
arity, peek, precedence, #type
Constructor Details
#initialize(*args) ⇒ Function
Returns a new instance of Function.
10
11
12
|
# File 'lib/dentaku/ast/function.rb', line 10
def initialize(*args)
@args = args
end
|
Class Method Details
.get(name) ⇒ Object
18
19
20
|
# File 'lib/dentaku/ast/function.rb', line 18
def self.get(name)
registry.get(name)
end
|
.numeric(value) ⇒ Numeric
An Exception will be raised if a value is passed that cannot be cast to a Number.
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/dentaku/ast/function.rb', line 36
def self.numeric(value)
return value if value.is_a?(::Numeric)
if value.is_a?(::String)
number = value[/\A-?\d*\.?\d+\z/]
return number.include?('.') ? BigDecimal(number, DIG) : number.to_i if number
end
raise Dentaku::ArgumentError.for(:incompatible_type, value: value, for: Numeric),
"'#{value || value.class}' is not coercible to numeric"
end
|
.register(name, type, implementation) ⇒ Object
22
23
24
|
# File 'lib/dentaku/ast/function.rb', line 22
def self.register(name, type, implementation)
registry.register(name, type, implementation)
end
|
.register_class(name, function_class) ⇒ Object
26
27
28
|
# File 'lib/dentaku/ast/function.rb', line 26
def self.register_class(name, function_class)
registry.register_class(name, function_class)
end
|
.registry ⇒ Object
30
31
32
|
# File 'lib/dentaku/ast/function.rb', line 30
def self.registry
@registry ||= FunctionRegistry.new
end
|
Instance Method Details
#dependencies(context = {}) ⇒ Object
14
15
16
|
# File 'lib/dentaku/ast/function.rb', line 14
def dependencies(context = {})
@args.flat_map { |a| a.dependencies(context) }
end
|