Class: Code::Node::Dictionary::KeyValue

Inherits:
Code::Node
  • Object
show all
Defined in:
lib/code/node/dictionary.rb

Instance Method Summary collapse

Methods inherited from Code::Node

#resolve

Constructor Details

#initialize(parsed) ⇒ KeyValue

Returns a new instance of KeyValue.



7
8
9
10
11
12
13
14
15
# File 'lib/code/node/dictionary.rb', line 7

def initialize(parsed)
  if parsed.key?(:statement)
    @key = Node::Statement.new(parsed.delete(:statement))
  elsif parsed.key?(:name)
    @key = Node::String.new([{ text: parsed.delete(:name) }])
  end

  @value = Node::Code.new(parsed.delete(:value)) if parsed[:value]
end

Instance Method Details

#evaluate(**args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/code/node/dictionary.rb', line 17

def evaluate(**args)
  key = @key.evaluate(**args)

  if @value
    value = @value.evaluate(**args)
    [key, value]
  else
    [key, key]
  end
end