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
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Node
arity, #name, precedence, resolve_class, #type
Constructor Details
#initialize(*args) ⇒ Function
Returns a new instance of Function.
12
13
14
|
# File 'lib/dentaku/ast/function.rb', line 12
def initialize(*args)
@args = args
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
7
8
9
|
# File 'lib/dentaku/ast/function.rb', line 7
def args
@args
end
|
Class Method Details
.get(name) ⇒ Object
25
26
27
|
# File 'lib/dentaku/ast/function.rb', line 25
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.
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/dentaku/ast/function.rb', line 43
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
29
30
31
|
# File 'lib/dentaku/ast/function.rb', line 29
def self.register(name, type, implementation)
registry.register(name, type, implementation)
end
|
.register_class(name, function_class) ⇒ Object
33
34
35
|
# File 'lib/dentaku/ast/function.rb', line 33
def self.register_class(name, function_class)
registry.register_class(name, function_class)
end
|
.registry ⇒ Object
37
38
39
|
# File 'lib/dentaku/ast/function.rb', line 37
def self.registry
@registry ||= FunctionRegistry.new
end
|
Instance Method Details
#accept(visitor) ⇒ Object
16
17
18
|
# File 'lib/dentaku/ast/function.rb', line 16
def accept(visitor)
visitor.visit_function(self)
end
|
#dependencies(context = {}) ⇒ Object
20
21
22
23
|
# File 'lib/dentaku/ast/function.rb', line 20
def dependencies(context = {})
@args.each_with_index
.flat_map { |a, _| a.dependencies(context) }
end
|