code-ruby 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +5 -3
  4. data/Rakefile +5 -0
  5. data/bin/code +6 -0
  6. data/lib/code/node/base_10.rb +2 -2
  7. data/lib/code/node/base_16.rb +1 -5
  8. data/lib/code/node/base_2.rb +1 -5
  9. data/lib/code/node/base_8.rb +1 -5
  10. data/lib/code/node/call.rb +4 -4
  11. data/lib/code/node/code.rb +2 -1
  12. data/lib/code/node/decimal.rb +1 -4
  13. data/lib/code/node/dictionary.rb +6 -2
  14. data/lib/code/node/function.rb +3 -3
  15. data/lib/code/node/function_parameter.rb +5 -1
  16. data/lib/code/node/if.rb +2 -1
  17. data/lib/code/node/list.rb +2 -1
  18. data/lib/code/node/statement.rb +23 -23
  19. data/lib/code/node/string.rb +2 -1
  20. data/lib/code/object/argument.rb +4 -3
  21. data/lib/code/object/boolean.rb +4 -24
  22. data/lib/code/object/class.rb +3 -19
  23. data/lib/code/object/code.rb +16 -0
  24. data/lib/code/object/context.rb +6 -9
  25. data/lib/code/object/date.rb +25 -17
  26. data/lib/code/object/decimal.rb +30 -38
  27. data/lib/code/object/dictionary.rb +6 -21
  28. data/lib/code/object/duration.rb +7 -21
  29. data/lib/code/object/function.rb +29 -45
  30. data/lib/code/object/global.rb +56 -40
  31. data/lib/code/object/identifier_list.rb +0 -4
  32. data/lib/code/object/integer.rb +23 -46
  33. data/lib/code/object/json.rb +29 -0
  34. data/lib/code/object/list.rb +4 -21
  35. data/lib/code/object/nothing.rb +2 -20
  36. data/lib/code/object/parameter.rb +51 -0
  37. data/lib/code/object/range.rb +12 -27
  38. data/lib/code/object/string.rb +6 -27
  39. data/lib/code/object/time.rb +14 -24
  40. data/lib/code/object.rb +155 -15
  41. data/lib/code/parser.rb +1 -1
  42. data/lib/code/type.rb +10 -2
  43. data/lib/code/version.rb +1 -1
  44. data/lib/code-ruby.rb +6 -0
  45. data/lib/code.rb +8 -5
  46. data/spec/code/object/dictionary_spec.rb +0 -2
  47. data/spec/code_spec.rb +141 -29
  48. metadata +6 -3
  49. data/lib/code/object/number.rb +0 -11
@@ -2,23 +2,15 @@
2
2
 
3
3
  class Code
4
4
  class Object
5
- class Decimal < ::Code::Object::Number
6
- attr_reader :raw
7
-
8
- def initialize(decimal, exponent: nil)
9
- decimal = decimal.raw if decimal.is_a?(Decimal)
10
- @raw = BigDecimal(decimal)
11
-
12
- return unless exponent
13
- unless exponent.is_a?(Number)
14
- raise ::Code::Error::TypeError, "exponent is not a number"
15
- end
16
-
17
- @raw *= 10**exponent.raw
18
- end
19
-
20
- def self.name
21
- "Decimal"
5
+ class Decimal < Object
6
+ def initialize(*args, **_kargs, &_block)
7
+ decimal = args.first || "0"
8
+ exponent = args.second || "0"
9
+ decimal = decimal.raw if decimal.is_an?(Object)
10
+ exponent = exponent.raw if exponent.is_an?(Object)
11
+ @raw = decimal.to_d * 10**exponent.to_d
12
+ rescue FloatDomainError => e
13
+ raise Error, "#{decimal.inspect} * 10**#{exponent.inspect} is invalid"
22
14
  end
23
15
 
24
16
  def call(**args)
@@ -28,49 +20,49 @@ class Code
28
20
 
29
21
  case operator.to_s
30
22
  when "%", "modulo"
31
- sig(args) { Number }
23
+ sig(args) { Integer | Decimal }
32
24
  code_modulo(value)
33
25
  when "&", "bitwise_and"
34
- sig(args) { Number }
26
+ sig(args) { Integer | Decimal }
35
27
  code_bitwise_and(value)
36
28
  when "*", "multiplication"
37
- sig(args) { Number }
29
+ sig(args) { Integer | Decimal }
38
30
  code_multiplication(value)
39
31
  when "**", "power"
40
- sig(args) { Number }
32
+ sig(args) { Integer | Decimal }
41
33
  code_power(value)
42
34
  when "+", "plus"
43
35
  sig(args) { Object.maybe }
44
36
  value ? code_plus(value) : self
45
37
  when "-", "minus"
46
- sig(args) { Number.maybe }
38
+ sig(args) { (Integer | Decimal).maybe }
47
39
  value ? code_minus(value) : code_unary_minus
48
40
  when "/", "division"
49
- sig(args) { Number }
41
+ sig(args) { Integer | Decimal }
50
42
  code_division(value)
51
43
  when "<", "inferior"
52
- sig(args) { Number }
44
+ sig(args) { Integer | Decimal }
53
45
  code_inferior(value)
54
46
  when "<<", "left_shift"
55
- sig(args) { Number }
47
+ sig(args) { Integer | Decimal }
56
48
  code_left_shift(value)
57
49
  when "<=", "inferior_or_equal"
58
- sig(args) { Number }
50
+ sig(args) { Integer | Decimal }
59
51
  code_inferior_or_equal(value)
60
52
  when "<=>", "compare"
61
- sig(args) { Number }
53
+ sig(args) { Integer | Decimal }
62
54
  code_compare(value)
63
55
  when ">", "superior"
64
- sig(args) { Number }
56
+ sig(args) { Integer | Decimal }
65
57
  code_superior(value)
66
58
  when ">=", "superior_or_equal"
67
- sig(args) { Number }
59
+ sig(args) { Integer | Decimal }
68
60
  code_superior_or_equal(value)
69
61
  when ">>", "right_shift"
70
- sig(args) { Number }
62
+ sig(args) { Integer | Decimal }
71
63
  code_right_shift(value)
72
64
  when "^", "bitwise_xor"
73
- sig(args) { Number }
65
+ sig(args) { Integer | Decimal }
74
66
  code_bitwise_xor(value)
75
67
  when "abs"
76
68
  sig(args)
@@ -136,7 +128,7 @@ class Code
136
128
  sig(args)
137
129
  code_zero?
138
130
  when "|", "bitwise_or"
139
- sig(args) { Number }
131
+ sig(args) { Integer | Decimal }
140
132
  code_bitwise_or(value)
141
133
  else
142
134
  super
@@ -226,7 +218,7 @@ class Code
226
218
  end
227
219
 
228
220
  def code_plus(other)
229
- if other.is_a?(Number)
221
+ if other.is_an?(Integer) || other.is_a?(Decimal)
230
222
  Decimal.new(raw + other.raw)
231
223
  else
232
224
  String.new(to_s + other.to_s)
@@ -303,16 +295,16 @@ class Code
303
295
  Boolean.new(raw.zero?)
304
296
  end
305
297
 
306
- def inspect
307
- to_s
298
+ def whole?
299
+ whole == raw
308
300
  end
309
301
 
310
- def to_s
311
- raw.to_s("F")
302
+ def whole
303
+ raw.round
312
304
  end
313
305
 
314
306
  def as_json(...)
315
- raw.as_json(...)
307
+ whole? ? whole.as_json(...) : super
316
308
  end
317
309
  end
318
310
  end
@@ -3,15 +3,12 @@
3
3
  class Code
4
4
  class Object
5
5
  class Dictionary < ::Code::Object
6
- attr_reader :raw
7
-
8
- def initialize(raw = {})
9
- raw = raw.raw if raw.is_a?(Dictionary)
10
- @raw = raw.to_h
11
- end
12
-
13
- def self.name
14
- "Dictionary"
6
+ def initialize(*args, **_kargs, &_block)
7
+ @raw = (args.first.presence || {})
8
+ .as_json
9
+ .to_h
10
+ .transform_keys { |key| Json.to_code(key) }
11
+ .transform_values { |value| Json.to_code(value) }
15
12
  end
16
13
 
17
14
  def call(**args)
@@ -654,18 +651,6 @@ class Code
654
651
  def code_zero?
655
652
  code_size.code_zero?
656
653
  end
657
-
658
- def inspect
659
- to_s
660
- end
661
-
662
- def to_s
663
- "{#{raw.map { |key, value| "#{key.inspect} => #{value.inspect}" }.join(", ")}}"
664
- end
665
-
666
- def as_json(...)
667
- raw.as_json(...)
668
- end
669
654
  end
670
655
  end
671
656
  end
@@ -3,15 +3,13 @@
3
3
  class Code
4
4
  class Object
5
5
  class Duration < Object
6
- attr_reader :raw
7
-
8
- def initialize(duration)
9
- duration = duration.raw if duration.is_a?(Duration)
10
- @raw = duration
11
- end
12
-
13
- def self.name
14
- "Duration"
6
+ def initialize(*args, **_kargs, &_block)
7
+ raw = args.first || 0.seconds
8
+ raw = raw.raw if raw.is_an?(Object)
9
+ raw = raw.iso8601 if raw.is_an?(::ActiveSupport::Duration)
10
+ @raw = ::ActiveSupport::Duration.parse(raw.to_s)
11
+ rescue ::ActiveSupport::Duration::ISO8601Parser::ParsingError
12
+ raise Error, "#{raw.inspect} is not a valid duration"
15
13
  end
16
14
 
17
15
  def call(**args)
@@ -36,18 +34,6 @@ class Code
36
34
  def code_from_now
37
35
  Time.new(raw.from_now)
38
36
  end
39
-
40
- def inspect
41
- to_s
42
- end
43
-
44
- def to_s
45
- raw.to_s
46
- end
47
-
48
- def as_json(...)
49
- raw.as_json(...)
50
- end
51
37
  end
52
38
  end
53
39
  end
@@ -2,22 +2,20 @@
2
2
 
3
3
  class Code
4
4
  class Object
5
- class Function < ::Code::Object
5
+ class Function < Object
6
6
  attr_reader :parameters, :body
7
7
 
8
- def initialize(parameters:, body:)
9
- @parameters = parameters.presence || []
10
- @body = body.presence || Node::Code.new
11
- end
12
-
13
- def self.name
14
- "Function"
8
+ def initialize(*args, **_kargs, &_block)
9
+ @parameters = List.new(args.first.presence || [])
10
+ @parameters.raw.map! { |parameter| Parameter.new(parameter) }
11
+ @body = Code.new(args.second.presence || Nothing.new)
12
+ @raw = List.new(parameters, body)
15
13
  end
16
14
 
17
15
  def call(**args)
18
16
  operator = args.fetch(:operator, nil)
19
17
  arguments = args.fetch(:arguments, [])
20
- globals = multi_fetch(args, *::Code::GLOBALS)
18
+ globals = multi_fetch(args, *GLOBALS)
21
19
 
22
20
  case operator.to_s
23
21
  when "", "call"
@@ -29,66 +27,52 @@ class Code
29
27
  end
30
28
 
31
29
  def code_call(*arguments, **globals)
32
- context = Context.new({}, parent: globals[:context])
30
+ context = Context.new({}, globals[:context])
33
31
 
34
- parameters.each.with_index do |parameter, index|
35
- if parameter.regular?
36
- if parameter.regular_splat?
37
- context.code_set(
38
- parameter.name,
39
- List.new(arguments.select(&:regular?).map(&:value))
40
- )
41
- elsif parameter.keyword_splat?
42
- context.code_set(
43
- parameter.name,
44
- Dictionary.new(
45
- arguments.select(&:keyword?).map(&:name_value).to_h
46
- )
32
+ parameters.raw.each.with_index do |parameter, index|
33
+ if parameter.regular_splat?
34
+ context.code_set(
35
+ parameter.code_name,
36
+ List.new(arguments.select(&:regular?).map(&:value))
37
+ )
38
+ elsif parameter.keyword_splat?
39
+ context.code_set(
40
+ parameter.code_name,
41
+ Dictionary.new(
42
+ arguments.select(&:keyword?).map(&:name_value).to_h
47
43
  )
48
- else
49
- argument = arguments[index]&.value
50
- argument = parameter.evaluate(**globals) if argument.nil?
51
- context.code_set(parameter.name, argument)
52
- end
44
+ )
53
45
  elsif parameter.keyword?
54
46
  argument =
55
47
  arguments
56
- .detect { |argument| argument.name == parameter.name }
48
+ .detect { |argument| argument.name == parameter.code_name }
57
49
  &.value
58
50
  argument = parameter.evaluate(**globals) if argument.nil?
59
- context.code_set(parameter.name, argument)
51
+ context.code_set(parameter.code_name, argument)
52
+ elsif parameter.regular?
53
+ argument = arguments[index]&.value
54
+ argument = parameter.evaluate(**globals) if argument.nil?
55
+ context.code_set(parameter.code_name, argument)
60
56
  end
61
57
  end
62
58
 
63
59
  body.evaluate(**globals, context:)
64
60
  end
65
61
 
66
- def inspect
67
- "function"
68
- end
69
-
70
62
  def signature_for_call
71
- parameters.inject([]) do |signature, parameter|
63
+ parameters.raw.inject([]) do |signature, parameter|
72
64
  if parameter.keyword?
73
65
  if signature.last.is_a?(::Hash)
74
- signature.last[parameter.name] = Object
66
+ signature.last.code_set(parameter.code_name, Object)
75
67
  signature
76
68
  else
77
- signature + [{ parameter.name => Object }]
69
+ signature + [{ parameter.code_name => Object }]
78
70
  end
79
71
  else
80
72
  signature + [Object]
81
73
  end
82
74
  end + [Object.repeat]
83
75
  end
84
-
85
- def to_s
86
- ""
87
- end
88
-
89
- def as_json(...)
90
- raw.as_json(...)
91
- end
92
76
  end
93
77
  end
94
78
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  class Code
4
4
  class Object
5
- class Global < ::Code::Object
6
- def self.name
7
- "Global"
5
+ class Global < Object
6
+ def initialize(...)
7
+ super
8
8
  end
9
9
 
10
10
  def call(**args)
@@ -14,62 +14,78 @@ class Code
14
14
  context = args.fetch(:context)
15
15
  globals = multi_fetch(args, *GLOBALS)
16
16
  value = arguments.first&.value
17
+ values = arguments.map(&:value)
17
18
 
18
19
  case operator.to_s
19
20
  when "Boolean"
20
- sig(args) { Object.maybe }
21
- value ? value.code_to_boolean : Class.new(Boolean)
21
+ sig(args) { Object.repeat }
22
+ value ? Boolean.new(*values) : Class.new(Boolean)
22
23
  when "break"
23
- sig(args) { Object.maybe }
24
+ sig(args) { Object.repeat }
24
25
  raise Error::Break, value || Nothing.new
25
26
  when "next"
26
- sig(args) { Object.maybe }
27
+ sig(args) { Object.repeat }
27
28
  raise Error::Next, value || Nothing.new
28
29
  when "Class"
29
- sig(args) { Object.maybe }
30
- value ? value.code_to_class : Class.new(Class)
30
+ sig(args) { Object.repeat }
31
+ value ? Class.new(*values) : Class.new(Class)
31
32
  when "Date"
32
- sig(args) { Object.maybe }
33
- value ? value.code_to_date : Class.new(Date)
33
+ sig(args) { Object.repeat }
34
+ value ? Date.new(*values) : Class.new(Date)
34
35
  when "Decimal"
35
- sig(args) { Object.maybe }
36
- value ? value.code_to_decimal : Class.new(Decimal)
36
+ sig(args) { Object.repeat }
37
+ value ? Decimal.new(*values) : Class.new(Decimal)
37
38
  when "Dictionary"
38
- sig(args) { Object.maybe }
39
- value ? value.code_to_dictionnary : Class.new(Dictionary)
40
- when "fetch"
41
- sig(args) { [Object, Function.maybe] }
42
- context.code_fetch(*arguments.map(&:value), **globals)
39
+ sig(args) { Object.repeat }
40
+ value ? Dictionary.new(*values) : Class.new(Dictionary)
41
+ when "Duration"
42
+ sig(args) { Object.repeat }
43
+ value ? Duration.new(*values) : Class.new(Duration)
43
44
  when "Function"
44
- sig(args) { Object.maybe }
45
- value ? value.code_to_function : Class.new(Function)
45
+ sig(args)
46
+ Class.new(Function)
46
47
  when "Integer"
47
- sig(args) { Object.maybe }
48
- value ? value.code_to_integer : Class.new(Integer)
48
+ sig(args) { Object.repeat }
49
+ value ? Integer.new(*values) : Class.new(Integer)
49
50
  when "List"
50
- sig(args) { Object.maybe }
51
- value ? value.code_to_list : Class.new(List)
51
+ sig(args) { Object.repeat }
52
+ value ? List.new(*values) : Class.new(List)
52
53
  when "Nothing"
53
- sig(args) { Object.maybe }
54
- value ? value.code_to_nothing : Class.new(Nothing)
55
- when "Number"
56
- sig(args) { Object.maybe }
57
- value ? value.code_to_number : Class.new(Number)
54
+ sig(args) { Object.repeat }
55
+ value ? Nothing.new(*values) : Class.new(Nothing)
56
+ when "context"
57
+ sig(args)
58
+ context
58
59
  when "Object"
59
- sig(args) { Object.maybe }
60
- value ? value.code_to_object : Class.new(Object)
60
+ sig(args)
61
+ Class.new(Object)
61
62
  when "Range"
62
- sig(args) { Object.maybe }
63
- value ? value.code_to_range : Class.new(Range)
63
+ sig(args) { Object.repeat }
64
+ value ? Range.new(*values) : Class.new(Range)
64
65
  when "String"
65
- sig(args) { Object.maybe }
66
- value ? value.code_to_string : Class.new(String)
66
+ sig(args) { Object.repeat }
67
+ value ? String.new(*values) : Class.new(String)
67
68
  when "Time"
68
- sig(args) { Object.maybe }
69
- value ? value.code_to_time : Class.new(Time)
70
- when "context"
71
- sig(args) { String.maybe }
72
- value ? context.code_get(value) || Nothing.new : context
69
+ sig(args) { Object.repeat }
70
+ value ? Time.new(*values) : Class.new(Time)
71
+ when "Context"
72
+ sig(args) { Object.repeat }
73
+ value ? Context.new(*values) : Class.new(Context)
74
+ when "Code"
75
+ sig(args) { Object.repeat }
76
+ value ? Code.new(*values) : Class.new(Code)
77
+ when "Argument"
78
+ sig(args) { Object.repeat }
79
+ value ? Argument.new(*values) : Class.new(Argument)
80
+ when "Parameter"
81
+ sig(args) { Object.repeat }
82
+ value ? Parameter.new(*values) : Class.new(Parameter)
83
+ when "Range"
84
+ sig(args) { Object.repeat }
85
+ value ? Range.new(*values) : Class.new(Range)
86
+ when "IdentifierList"
87
+ sig(args) { Object.repeat }
88
+ value ? IdentifierList.new(*values) : Class.new(IdentifierList)
73
89
  when "evaluate"
74
90
  sig(args) { Object }
75
91
  Code.evaluate(value.to_s)
@@ -3,10 +3,6 @@
3
3
  class Code
4
4
  class Object
5
5
  class IdentifierList < List
6
- def self.name
7
- "IdentifierList"
8
- end
9
-
10
6
  def call(**args)
11
7
  operator = args.fetch(:operator, nil)
12
8
  arguments = args.fetch(:arguments, [])
@@ -2,22 +2,15 @@
2
2
 
3
3
  class Code
4
4
  class Object
5
- class Integer < Number
6
- attr_reader :raw
7
-
8
- def initialize(whole, exponent: nil)
9
- whole = whole.raw if whole.is_a?(Integer)
10
- @raw = whole.to_i
11
- return unless exponent
12
-
13
- exponent = exponent.raw if exponent.is_a?(Number)
14
- @raw *= 10**exponent
5
+ class Integer < Object
6
+ def initialize(*args, **_kargs, &_block)
7
+ whole = args.first || 0
8
+ exponent = args.second || 0
9
+ whole = whole.raw if whole.is_an?(Object)
10
+ exponent = exponent.raw if exponent.is_an?(Object)
11
+ @raw = whole.to_i * 10**exponent
15
12
  rescue FloatDomainError => e
16
- raise Error, e.message
17
- end
18
-
19
- def self.name
20
- "Integer"
13
+ raise Error, "#{decimal.inspect} * 10**#{exponent.inspect} is invalid"
21
14
  end
22
15
 
23
16
  def call(**args)
@@ -28,49 +21,49 @@ class Code
28
21
 
29
22
  case operator.to_s
30
23
  when "%", "modulo"
31
- sig(args) { Number }
24
+ sig(args) { Integer | Decimal }
32
25
  code_modulo(value)
33
26
  when "&", "bitwise_and"
34
- sig(args) { Number }
27
+ sig(args) { Integer | Decimal }
35
28
  code_bitwise_and(value)
36
29
  when "*", "multiplication", "×"
37
- sig(args) { Number | String }
30
+ sig(args) { Integer | Decimal | String }
38
31
  code_multiplication(value)
39
32
  when "**", "power"
40
- sig(args) { Number }
33
+ sig(args) { Integer | Decimal }
41
34
  code_power(value)
42
35
  when "+", "plus", "self"
43
36
  sig(args) { Object.maybe }
44
37
  value ? code_plus(value) : code_self
45
38
  when "-", "minus", "unary_minus"
46
- sig(args) { Number.maybe }
39
+ sig(args) { Integer | Decimal.maybe }
47
40
  value ? code_minus(value) : code_unary_minus
48
41
  when "/", "division", "÷"
49
- sig(args) { Number }
42
+ sig(args) { Integer | Decimal }
50
43
  code_division(value)
51
44
  when "<", "inferior"
52
- sig(args) { Number }
45
+ sig(args) { Integer | Decimal }
53
46
  code_inferior(value)
54
47
  when "<<", "left_shift"
55
- sig(args) { Number }
48
+ sig(args) { Integer | Decimal }
56
49
  code_left_shift(value)
57
50
  when "<=", "inferior_or_equal"
58
- sig(args) { Number }
51
+ sig(args) { Integer | Decimal }
59
52
  code_inferior_or_equal(value)
60
53
  when "<=>", "compare"
61
- sig(args) { Number }
54
+ sig(args) { Integer | Decimal }
62
55
  code_compare(value)
63
56
  when ">", "superior"
64
- sig(args) { Number }
57
+ sig(args) { Integer | Decimal }
65
58
  code_superior(value)
66
59
  when ">=", "superior_or_equal"
67
- sig(args) { Number }
60
+ sig(args) { Integer | Decimal }
68
61
  code_superior_or_equal(value)
69
62
  when ">>", "right_shift"
70
- sig(args) { Number }
63
+ sig(args) { Integer | Decimal }
71
64
  code_right_shift(value)
72
65
  when "^", "bitwise_xor"
73
- sig(args) { Number }
66
+ sig(args) { Integer | Decimal }
74
67
  code_bitwise_xor(value)
75
68
  when "abs"
76
69
  sig(args)
@@ -163,7 +156,7 @@ class Code
163
156
  sig(args)
164
157
  code_zero?
165
158
  when "|", "bitwise_or"
166
- sig(args) { Number }
159
+ sig(args) { Integer | Decimal }
167
160
  code_bitwise_or(value)
168
161
  else
169
162
  super
@@ -394,22 +387,6 @@ class Code
394
387
  def code_days
395
388
  Duration.new(raw.days)
396
389
  end
397
-
398
- def inspect
399
- to_s
400
- end
401
-
402
- def succ
403
- Integer.new(raw + 1)
404
- end
405
-
406
- def to_s
407
- raw.to_s
408
- end
409
-
410
- def as_json(...)
411
- raw.as_json(...)
412
- end
413
390
  end
414
391
  end
415
392
  end
@@ -0,0 +1,29 @@
1
+ class Code
2
+ class Object
3
+ class Json < Object
4
+ def self.to_code(json)
5
+ if json.is_an?(Object)
6
+ json
7
+ elsif json.is_a?(::Hash)
8
+ Dictionary.new(json)
9
+ elsif json.is_a?(::Array)
10
+ List.new(json)
11
+ elsif json.is_a?(::String)
12
+ String.new(json)
13
+ elsif json.is_a?(::Float)
14
+ Decimal.new(json)
15
+ elsif json.is_an?(::Integer)
16
+ Integer.new(json)
17
+ elsif json.is_a?(::TrueClass)
18
+ Boolean.new(json)
19
+ elsif json.is_a?(::FalseClass)
20
+ Boolean.new(json)
21
+ elsif json.is_a?(::NilClass)
22
+ Nothing.new(json)
23
+ else
24
+ Nothing.new
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,18 +2,13 @@
2
2
 
3
3
  class Code
4
4
  class Object
5
- class List < ::Code::Object
6
- attr_reader :raw
7
-
8
- def initialize(raw = [])
9
- raw = raw.raw if raw.is_a?(List)
5
+ class List < Object
6
+ def initialize(*args, **_kargs, &_block)
7
+ raw = args.first || Nothing.new
8
+ raw = raw.raw if raw.is_an?(Object)
10
9
  @raw = raw.to_a
11
10
  end
12
11
 
13
- def self.name
14
- "List"
15
- end
16
-
17
12
  def call(**args)
18
13
  operator = args.fetch(:operator, nil)
19
14
  arguments = args.fetch(:arguments, [])
@@ -234,18 +229,6 @@ class Code
234
229
  def code_sum
235
230
  raw.inject(&:code_plus) || Nothing.new
236
231
  end
237
-
238
- def inspect
239
- to_s
240
- end
241
-
242
- def to_s
243
- "[#{raw.map(&:inspect).join(", ")}]"
244
- end
245
-
246
- def as_json(...)
247
- raw.as_json(...)
248
- end
249
232
  end
250
233
  end
251
234
  end