Class: Zapata::Primitive::Array

Inherits:
Base
  • Object
show all
Defined in:
lib/zapata/primitive/array.rb

Instance Attribute Summary

Attributes inherited from Base

#code, #type

Instance Method Summary collapse

Methods inherited from Base

#dive_deeper, #initialize, #name, #return_with_missing_as_super, #return_with_super_as_missing

Constructor Details

This class inherits a constructor from Zapata::Primitive::Base

Instance Method Details

#nodeObject



6
7
8
9
10
# File 'lib/zapata/primitive/array.rb', line 6

def node
  body = @code
  type = @code.type
  OpenStruct.new(type: type, body: body)
end

#to_aObject



12
13
14
# File 'lib/zapata/primitive/array.rb', line 12

def to_a
  value
end

#to_rawObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zapata/primitive/array.rb', line 16

def to_raw
  value = node.body.to_a.map do |node|
    primitive = Diver.dive(node)
    raw = primitive.to_raw

    if raw.type == :super
      predicted = Predictor::Value.new(raw.value).choose.to_raw
      return_with_super_as_missing(predicted, primitive)
    else
      raw
    end
  end

  Raw.new(:array, value)
end