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.



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

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

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

  super(parsed)
end

Instance Method Details

#evaluate(**args) ⇒ Object



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
# File 'lib/code/node/call.rb', line 37

def evaluate(**args)
  arguments = []

  @arguments.each do |argument|
    if argument.keyword?
      if arguments.last&.value.is_a?(Object::Dictionary)
        arguments.last.value[argument.name] = argument.evaluate(
          **args
        ).value
      else
        arguments << Object::Argument.new(
          Object::Dictionary.new(
            { argument.name => argument.evaluate(**args).value }
          )
        )
      end
    else
      arguments << argument.evaluate(**args)
    end
  end

  arguments << @block.evaluate(**args) if @block

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

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

#resolve(**_args) ⇒ Object



65
66
67
# File 'lib/code/node/call.rb', line 65

def resolve(**_args)
  Object::String.new(@name)
end