Class: Kumi::Core::Analyzer::ConstantEvaluator
- Inherits:
-
Object
- Object
- Kumi::Core::Analyzer::ConstantEvaluator
- Defined in:
- lib/kumi/core/analyzer/constant_evaluator.rb
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate ⇒ Object
-
#initialize(call_node, registry, known_constants) ⇒ ConstantEvaluator
constructor
A new instance of ConstantEvaluator.
Constructor Details
#initialize(call_node, registry, known_constants) ⇒ ConstantEvaluator
Returns a new instance of ConstantEvaluator.
13 14 15 16 17 |
# File 'lib/kumi/core/analyzer/constant_evaluator.rb', line 13 def initialize(call_node, registry, known_constants) @node = call_node @registry = registry @known_constants = known_constants end |
Class Method Details
.evaluate(call_node, registry, known_constants = {}) ⇒ Object
9 10 11 |
# File 'lib/kumi/core/analyzer/constant_evaluator.rb', line 9 def self.evaluate(call_node, registry, known_constants = {}) new(call_node, registry, known_constants).evaluate end |
Instance Method Details
#evaluate ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kumi/core/analyzer/constant_evaluator.rb', line 19 def evaluate arg_values = @node.args.map { |arg| resolve_constant_value(arg) } return nil if arg_values.any?(&:nil?) func = @registry.function(@node.fn) return nil unless func.respond_to?(:folding_class_method) && func.folding_class_method method_name = func.folding_class_method.to_sym ConstantFoldingHelpers.send(method_name, *arg_values) rescue StandardError nil end |