Class: EleetScript::ListBase

Inherits:
Object
  • Object
show all
Defined in:
lib/lang/runtime/base_classes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListBase

Returns a new instance of ListBase.



9
10
11
12
# File 'lib/lang/runtime/base_classes.rb', line 9

def initialize
  @array_value = []
  @hash_value = {}
end

Instance Attribute Details

#array_valueObject

Returns the value of attribute array_value.



7
8
9
# File 'lib/lang/runtime/base_classes.rb', line 7

def array_value
  @array_value
end

#hash_valueObject

Returns the value of attribute hash_value.



7
8
9
# File 'lib/lang/runtime/base_classes.rb', line 7

def hash_value
  @hash_value
end

Instance Method Details

#clearObject



41
42
43
44
# File 'lib/lang/runtime/base_classes.rb', line 41

def clear
  array_value.clear
  hash_value.clear
end

#cloneObject



19
20
21
# File 'lib/lang/runtime/base_classes.rb', line 19

def clone
  dup
end

#dupObject



23
24
25
26
27
28
# File 'lib/lang/runtime/base_classes.rb', line 23

def dup
  ListBase.new.tap do |lst|
    lst.array_value = array_value.dup
    lst.hash_value = hash_value.dup
  end
end

#merge!(o) ⇒ Object



14
15
16
17
# File 'lib/lang/runtime/base_classes.rb', line 14

def merge!(o)
  array_value.concat(o.array_value)
  hash_value.merge!(o.hash_value)
end

#to_hObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/lang/runtime/base_classes.rb', line 30

def to_h
  {}.tap do |hash|
    array_value.map.with_index do |value, index|
      hash[index] = value
    end
    hash_value.map do |key, value|
      hash[key] = value
    end
  end
end