Class: Code::Node::Call

Inherits:
Code::Node show all
Defined in:
lib/code/node/call.rb

Defined Under Namespace

Classes: Block

Instance Method Summary collapse

Constructor Details

#initialize(parsed) ⇒ Call

Returns a new instance of Call.



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/code/node/call.rb', line 23

def initialize(parsed)
  @name = parsed.delete(:name)
  @arguments =
    parsed
      .delete(:arguments) { [] }
      .map { |argument| Node::CallArgument.new(argument) }

  if parsed.key?(:block)
    @block = Node::Call::Block.new(parsed.delete(:block))
  end

  super(parsed)
end

Instance Method Details

#evaluate(**args) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/code/node/call.rb', line 37

def evaluate(**args)
  arguments = @arguments.map { |argument| argument.evaluate(**args) }
  arguments << @block.evaluate(**args) if @block

  name = ::Code::Object::String.new(@name)

  args.fetch(:object).call(operator: name, arguments: arguments, **args)
end