Class: Code::Object::IdentifierList

Inherits:
List show all
Defined in:
lib/code/object/identifier_list.rb

Instance Attribute Summary

Attributes inherited from List

#raw

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from List

#code_any?, #code_append, #code_detect, #code_each, #code_first, #code_flatten, #code_include?, #code_last, #code_map, #code_max, #code_max_by, #code_none?, #code_reduce, #code_reverse, #code_select, #code_size, #code_sort, #code_sum, #code_uniq, #initialize, #inspect, #to_s

Methods inherited from Code::Object

#<=>, #==, call, #code_and_operator, code_and_operator, #code_different, code_different, code_equal_equal, #code_equal_equal, code_equal_equal_equal, #code_equal_equal_equal, code_exclamation_point, #code_exclamation_point, code_exclusive_range, #code_exclusive_range, code_inclusive_range, #code_inclusive_range, code_or_operator, #code_or_operator, code_self, #code_self, code_to_string, #code_to_string, falsy?, #falsy?, #hash, inspect, #inspect, maybe, multi_fetch, #multi_fetch, repeat, sig, #sig, to_s, #to_s, truthy?, #truthy?, |

Constructor Details

This class inherits a constructor from Code::Object::List

Class Method Details

.nameObject



6
7
8
# File 'lib/code/object/identifier_list.rb', line 6

def self.name
  "IdentifierList"
end

Instance Method Details

#call(**args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/code/object/identifier_list.rb', line 10

def call(**args)
  operator = args.fetch(:operator, nil)
  arguments = args.fetch(:arguments, [])
  context = args.fetch(:context)
  value = arguments.first&.value

  case operator.to_s
  when /=$/
    sig(args) { Object }

    context = context.lookup!(raw.first)

    context =
      raw[..-2].reduce(context) do |context, identifier|
        context.code_fetch(identifier)
      end

    context.code_set(
      raw.last,
      if operator == "="
        value
      else
        context.fetch(raw.last).call(
          **args,
          operator: operator[..-2],
          arguments: [Argument.new(value)]
        )
      end
    )

    context.code_fetch(raw.last)
  else
    super
  end
end