Class: Halunke::DictionaryNode

Inherits:
Struct
  • Object
show all
Defined in:
lib/halunke/nodes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nodesObject

Returns the value of attribute nodes

Returns:

  • (Object)

    the current value of nodes



112
113
114
# File 'lib/halunke/nodes.rb', line 112

def nodes
  @nodes
end

#teObject

Returns the value of attribute te

Returns:

  • (Object)

    the current value of te



112
113
114
# File 'lib/halunke/nodes.rb', line 112

def te
  @te
end

#tsObject

Returns the value of attribute ts

Returns:

  • (Object)

    the current value of ts



112
113
114
# File 'lib/halunke/nodes.rb', line 112

def ts
  @ts
end

Instance Method Details

#==(other) ⇒ Object



123
124
125
126
# File 'lib/halunke/nodes.rb', line 123

def ==(other)
  other.is_a?(DictionaryNode) &&
    nodes == other.nodes
end

#eval(context) ⇒ Object



113
114
115
116
117
118
119
120
121
# File 'lib/halunke/nodes.rb', line 113

def eval(context)
  hash = {}
  nodes.each_slice(2) do |key, value|
    raise HInvalidDictionary.new("This key has no value", key.source_code_position) if value.nil?
    hash[key.eval(context)] = value.eval(context)
  end
  context["Dictionary"].create_instance(hash,
                                        source_code_position: source_code_position)
end

#source_code_positionObject



128
129
130
# File 'lib/halunke/nodes.rb', line 128

def source_code_position
  SourceCodePosition.new(ts, te)
end