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.



20
21
22
23
24
25
26
27
28
29
# File 'lib/code/node/call.rb', line 20

def initialize(parsed)
  return if parsed.blank?
  @name = parsed.delete(:name).presence
  @arguments = parsed.delete(:arguments).presence || []
  @arguments.map! { |argument| CallArgument.new(argument) }

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

Instance Method Details

#evaluate(**args) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/code/node/call.rb', line 31

def evaluate(**args)
  arguments = []

  (@arguments || []).each do |argument|
    if argument.keyword?
      if arguments.last&.value.is_a?(Object::Dictionary)
        arguments.last.value.code_set(
          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



60
61
62
# File 'lib/code/node/call.rb', line 60

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