Class: Code::Node::Call
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::Call
- Defined in:
- lib/code/node/call.rb
Defined Under Namespace
Classes: Block
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(parsed) ⇒ Call
constructor
A new instance of Call.
- #resolve(**_args) ⇒ Object
Constructor Details
#initialize(parsed) ⇒ Call
Returns a new instance of Call.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/code/node/call.rb', line 21 def initialize(parsed) return if parsed.blank? @name = parsed.delete(:name).presence @explicit_arguments = parsed.key?(:arguments) @arguments = parsed.delete(:arguments).presence || [] @arguments = [@arguments] unless @arguments.is_a?(Array) @arguments.map! { |argument| CallArgument.new(argument) } return unless parsed.key?(:block) @block = Call::Block.new(parsed.delete(:block).presence) end |
Instance Method Details
#evaluate(**args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/code/node/call.rb', line 35 def evaluate(**args) arguments = [] (@arguments || []).each do |argument| if argument.expansion? (arguments, argument, **args) elsif argument.keyword? if arguments.last.is_a?(Object::Dictionary) arguments.last.code_merge!(argument.evaluate(**args)) else arguments << argument.evaluate(**args) end else arguments << argument.evaluate(**args) end end arguments << @block.evaluate(**args) if @block name = Object::String.new(@name) object = args.fetch(:object) dynamic_result = object.code_dynamic_call( name, operator: name, arguments: Object::List.new(arguments), explicit_arguments: @explicit_arguments, **args ) return dynamic_result if dynamic_result object.call( operator: name, arguments: Object::List.new(arguments), explicit_arguments: @explicit_arguments, **args ) end |