code-ruby 0.13.1 → 0.14.1
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.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +15 -0
- data/.github/workflows/ci.yml +31 -0
- data/.rubocop.yml +8 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +52 -4
- data/bin/bundle-audit +31 -0
- data/bin/bundler-audit +31 -0
- data/bin/console +1 -0
- data/bin/rspec +31 -0
- data/bin/rubocop +31 -0
- data/lib/code/error.rb +0 -3
- data/lib/code/node/base_10.rb +4 -3
- data/lib/code/node/base_16.rb +1 -0
- data/lib/code/node/base_2.rb +1 -0
- data/lib/code/node/base_8.rb +1 -0
- data/lib/code/node/boolean.rb +1 -0
- data/lib/code/node/call.rb +14 -15
- data/lib/code/node/call_argument.rb +4 -4
- data/lib/code/node/code.rb +1 -0
- data/lib/code/node/decimal.rb +4 -3
- data/lib/code/node/dictionary.rb +5 -3
- data/lib/code/node/function.rb +1 -0
- data/lib/code/node/function_parameter.rb +14 -0
- data/lib/code/node/if.rb +6 -4
- data/lib/code/node/left_operation.rb +3 -3
- data/lib/code/node/list.rb +1 -0
- data/lib/code/node/negation.rb +1 -0
- data/lib/code/node/not.rb +1 -0
- data/lib/code/node/nothing.rb +1 -0
- data/lib/code/node/right_operation.rb +3 -2
- data/lib/code/node/splat.rb +1 -0
- data/lib/code/node/square_bracket.rb +1 -0
- data/lib/code/node/string.rb +3 -0
- data/lib/code/node/ternary.rb +4 -3
- data/lib/code/node/unary_minus.rb +1 -0
- data/lib/code/node/while.rb +4 -3
- data/lib/code/object/boolean.rb +2 -2
- data/lib/code/object/context.rb +1 -1
- data/lib/code/object/decimal.rb +9 -21
- data/lib/code/object/dictionary.rb +80 -113
- data/lib/code/object/function.rb +25 -35
- data/lib/code/object/global.rb +33 -32
- data/lib/code/object/identifier_list.rb +4 -4
- data/lib/code/object/integer.rb +14 -23
- data/lib/code/object/json.rb +10 -2
- data/lib/code/object/list.rb +50 -23
- data/lib/code/object/parameter.rb +18 -10
- data/lib/code/object/range.rb +33 -10
- data/lib/code/object/string.rb +2 -2
- data/lib/code/object/time.rb +4 -4
- data/lib/code/object.rb +31 -50
- data/lib/code/parser/string.rb +1 -1
- data/lib/code/type/repeat.rb +1 -1
- data/lib/code/type/sig.rb +1 -3
- data/lib/code/version.rb +1 -1
- data/lib/code-ruby.rb +2 -7
- data/lib/code.rb +1 -3
- data/spec/code/object/dictionary_spec.rb +6 -6
- data/spec/code_spec.rb +7 -8
- data/yarn.lock +4 -0
- metadata +10 -3
- data/lib/code/object/argument.rb +0 -27
data/lib/code/object/global.rb
CHANGED
@@ -4,22 +4,21 @@ class Code
|
|
4
4
|
class Object
|
5
5
|
class Global < Object
|
6
6
|
def initialize(...)
|
7
|
-
|
7
|
+
@raw = "global"
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(**args)
|
11
11
|
operator = args.fetch(:operator, nil)
|
12
|
-
arguments = args.fetch(:arguments,
|
12
|
+
arguments = args.fetch(:arguments, List.new)
|
13
13
|
output = args.fetch(:output)
|
14
14
|
context = args.fetch(:context)
|
15
|
-
|
16
|
-
value = arguments.
|
17
|
-
values = arguments.map(&:value)
|
15
|
+
multi_fetch(args, *GLOBALS)
|
16
|
+
value = arguments.code_first
|
18
17
|
|
19
18
|
case operator.to_s
|
20
19
|
when "Boolean"
|
21
20
|
sig(args) { Object.repeat }
|
22
|
-
|
21
|
+
arguments.any? ? Boolean.new(*arguments.raw) : Class.new(Boolean)
|
23
22
|
when "break"
|
24
23
|
sig(args) { Object.repeat }
|
25
24
|
raise Error::Break, value || Nothing.new
|
@@ -28,78 +27,80 @@ class Code
|
|
28
27
|
raise Error::Next, value || Nothing.new
|
29
28
|
when "Class"
|
30
29
|
sig(args) { Object.repeat }
|
31
|
-
|
30
|
+
arguments.any? ? Class.new(*arguments.raw) : Class.new(Class)
|
32
31
|
when "Date"
|
33
32
|
sig(args) { Object.repeat }
|
34
|
-
|
33
|
+
arguments.any? ? Date.new(*arguments.raw) : Class.new(Date)
|
35
34
|
when "Decimal"
|
36
35
|
sig(args) { Object.repeat }
|
37
|
-
|
36
|
+
arguments.any? ? Decimal.new(*arguments.raw) : Class.new(Decimal)
|
38
37
|
when "Dictionary"
|
39
38
|
sig(args) { Object.repeat }
|
40
|
-
|
39
|
+
if arguments.any?
|
40
|
+
Dictionary.new(*arguments.raw)
|
41
|
+
else
|
42
|
+
Class.new(Dictionary)
|
43
|
+
end
|
41
44
|
when "Duration"
|
42
45
|
sig(args) { Object.repeat }
|
43
|
-
|
46
|
+
arguments.any? ? Duration.new(*arguments.raw) : Class.new(Duration)
|
44
47
|
when "Function"
|
45
48
|
sig(args)
|
46
|
-
Class.new(Function)
|
49
|
+
arguments.any? ? Function.new(*arguments.raw) : Class.new(Function)
|
47
50
|
when "Integer"
|
48
51
|
sig(args) { Object.repeat }
|
49
|
-
|
52
|
+
arguments.any? ? Integer.new(*arguments.raw) : Class.new(Integer)
|
50
53
|
when "List"
|
51
54
|
sig(args) { Object.repeat }
|
52
|
-
|
55
|
+
arguments.any? ? List.new(*arguments.raw) : Class.new(List)
|
53
56
|
when "Nothing"
|
54
57
|
sig(args) { Object.repeat }
|
55
|
-
|
58
|
+
arguments.any? ? Nothing.new(*arguments.raw) : Class.new(Nothing)
|
56
59
|
when "context"
|
57
60
|
sig(args)
|
58
61
|
context
|
59
62
|
when "Object"
|
60
63
|
sig(args)
|
61
|
-
Class.new(Object)
|
64
|
+
arguments.any? ? Object.new(*arguments.raw) : Class.new(Object)
|
62
65
|
when "Range"
|
63
66
|
sig(args) { Object.repeat }
|
64
|
-
|
67
|
+
arguments.any? ? Range.new(*arguments.raw) : Class.new(Range)
|
65
68
|
when "String"
|
66
69
|
sig(args) { Object.repeat }
|
67
|
-
|
70
|
+
arguments.any? ? String.new(*arguments.raw) : Class.new(String)
|
68
71
|
when "Time"
|
69
72
|
sig(args) { Object.repeat }
|
70
|
-
|
73
|
+
arguments.any? ? Time.new(*arguments.raw) : Class.new(Time)
|
71
74
|
when "Context"
|
72
75
|
sig(args) { Object.repeat }
|
73
|
-
|
76
|
+
arguments.any? ? Context.new(*arguments.raw) : Class.new(Context)
|
74
77
|
when "Code"
|
75
78
|
sig(args) { Object.repeat }
|
76
|
-
|
77
|
-
when "Argument"
|
78
|
-
sig(args) { Object.repeat }
|
79
|
-
value ? Argument.new(*values) : Class.new(Argument)
|
79
|
+
arguments.any? ? Code.new(*arguments.raw) : Class.new(Code)
|
80
80
|
when "Parameter"
|
81
81
|
sig(args) { Object.repeat }
|
82
|
-
|
83
|
-
when "Range"
|
84
|
-
sig(args) { Object.repeat }
|
85
|
-
value ? Range.new(*values) : Class.new(Range)
|
82
|
+
arguments.any? ? Parameter.new(*arguments.raw) : Class.new(Parameter)
|
86
83
|
when "IdentifierList"
|
87
84
|
sig(args) { Object.repeat }
|
88
|
-
|
85
|
+
if arguments.any?
|
86
|
+
IdentifierList.new(*arguments.raw)
|
87
|
+
else
|
88
|
+
Class.new(IdentifierList)
|
89
|
+
end
|
89
90
|
when "evaluate"
|
90
91
|
sig(args) { Object }
|
91
92
|
Code.evaluate(value.to_s)
|
92
93
|
when "p"
|
93
94
|
sig(args) { Object.repeat }
|
94
|
-
output.puts(*arguments.
|
95
|
+
output.puts(*arguments.raw.map(&:inspect))
|
95
96
|
Nothing.new
|
96
97
|
when "print"
|
97
98
|
sig(args) { Object.repeat }
|
98
|
-
output.print(*arguments.
|
99
|
+
output.print(*arguments.raw)
|
99
100
|
Nothing.new
|
100
101
|
when "puts"
|
101
102
|
sig(args) { Object.repeat }
|
102
|
-
output.puts(*arguments.
|
103
|
+
output.puts(*arguments.raw)
|
103
104
|
Nothing.new
|
104
105
|
else
|
105
106
|
context = context.lookup!(operator)
|
@@ -5,9 +5,9 @@ class Code
|
|
5
5
|
class IdentifierList < List
|
6
6
|
def call(**args)
|
7
7
|
operator = args.fetch(:operator, nil)
|
8
|
-
arguments = args.fetch(:arguments,
|
8
|
+
arguments = args.fetch(:arguments, List.new)
|
9
9
|
context = args.fetch(:context)
|
10
|
-
value = arguments.
|
10
|
+
value = arguments.code_first
|
11
11
|
|
12
12
|
case operator.to_s
|
13
13
|
when /=$/
|
@@ -27,8 +27,8 @@ class Code
|
|
27
27
|
else
|
28
28
|
context.fetch(raw.last).call(
|
29
29
|
**args,
|
30
|
-
operator: operator
|
31
|
-
arguments:
|
30
|
+
operator: operator.chop,
|
31
|
+
arguments: List.new([value])
|
32
32
|
)
|
33
33
|
end
|
34
34
|
)
|
data/lib/code/object/integer.rb
CHANGED
@@ -9,15 +9,15 @@ class Code
|
|
9
9
|
whole = whole.raw if whole.is_an?(Object)
|
10
10
|
exponent = exponent.raw if exponent.is_an?(Object)
|
11
11
|
@raw = whole.to_i * 10**exponent
|
12
|
-
rescue FloatDomainError
|
12
|
+
rescue FloatDomainError
|
13
13
|
raise Error, "#{decimal.inspect} * 10**#{exponent.inspect} is invalid"
|
14
14
|
end
|
15
15
|
|
16
16
|
def call(**args)
|
17
17
|
operator = args.fetch(:operator, nil)
|
18
|
-
arguments = args.fetch(:arguments,
|
18
|
+
arguments = args.fetch(:arguments, List.new)
|
19
19
|
globals = multi_fetch(args, *GLOBALS)
|
20
|
-
value = arguments.
|
20
|
+
value = arguments.code_first
|
21
21
|
|
22
22
|
case operator.to_s
|
23
23
|
when "%", "modulo"
|
@@ -34,10 +34,10 @@ class Code
|
|
34
34
|
code_power(value)
|
35
35
|
when "+", "plus", "self"
|
36
36
|
sig(args) { Object.maybe }
|
37
|
-
|
37
|
+
arguments.any? ? code_plus(value) : code_self
|
38
38
|
when "-", "minus", "unary_minus"
|
39
39
|
sig(args) { Integer | Decimal.maybe }
|
40
|
-
|
40
|
+
arguments.any? ? code_minus(value) : code_unary_minus
|
41
41
|
when "/", "division", "÷"
|
42
42
|
sig(args) { Integer | Decimal }
|
43
43
|
code_division(value)
|
@@ -137,15 +137,6 @@ class Code
|
|
137
137
|
when "times"
|
138
138
|
sig(args) { Function }
|
139
139
|
code_times(value, **globals)
|
140
|
-
when "to_decimal"
|
141
|
-
sig(args)
|
142
|
-
code_to_decimal
|
143
|
-
when "to_integer"
|
144
|
-
sig(args)
|
145
|
-
code_to_integer
|
146
|
-
when "to_string"
|
147
|
-
sig(args)
|
148
|
-
code_to_string
|
149
140
|
when "truncate"
|
150
141
|
sig(args) { Integer.maybe }
|
151
142
|
code_truncate(value)
|
@@ -180,7 +171,7 @@ class Code
|
|
180
171
|
end
|
181
172
|
|
182
173
|
def code_ceil(n = nil)
|
183
|
-
n
|
174
|
+
n = Integer.new(0) if n.nil? || n.is_a?(Nothing)
|
184
175
|
Integer.new(raw.ceil(n.raw))
|
185
176
|
end
|
186
177
|
|
@@ -193,13 +184,13 @@ class Code
|
|
193
184
|
end
|
194
185
|
|
195
186
|
def code_decrement!(n = nil)
|
196
|
-
n
|
187
|
+
n = Integer.new(1) if n.nil? || n.is_a?(Nothing)
|
197
188
|
@raw -= n.raw
|
198
189
|
self
|
199
190
|
end
|
200
191
|
|
201
192
|
def code_decrement(n = nil)
|
202
|
-
n
|
193
|
+
n = Integer.new(1) if n.nil? || n.is_a?(Nothing)
|
203
194
|
Integer.new(raw - n.raw)
|
204
195
|
end
|
205
196
|
|
@@ -220,7 +211,7 @@ class Code
|
|
220
211
|
end
|
221
212
|
|
222
213
|
def code_floor(n = nil)
|
223
|
-
n
|
214
|
+
n = Integer.new(0) if n.nil? || n.is_a?(Nothing)
|
224
215
|
Integer.new(raw.floor(n.raw))
|
225
216
|
end
|
226
217
|
|
@@ -229,13 +220,13 @@ class Code
|
|
229
220
|
end
|
230
221
|
|
231
222
|
def code_increment!(n = nil)
|
232
|
-
n
|
223
|
+
n = Integer.new(1) if n.nil? || n.is_a?(Nothing)
|
233
224
|
@raw += n.raw
|
234
225
|
self
|
235
226
|
end
|
236
227
|
|
237
228
|
def code_increment(n = nil)
|
238
|
-
n
|
229
|
+
n = Integer.new(1) if n.nil? || n.is_a?(Nothing)
|
239
230
|
Integer.new(raw + n.raw)
|
240
231
|
end
|
241
232
|
|
@@ -312,7 +303,7 @@ class Code
|
|
312
303
|
end
|
313
304
|
|
314
305
|
def code_round(n = nil)
|
315
|
-
n
|
306
|
+
n = Integer.new(0) if n.nil? || n.is_a?(Nothing)
|
316
307
|
Integer.new(raw.round(n.raw))
|
317
308
|
end
|
318
309
|
|
@@ -355,7 +346,7 @@ class Code
|
|
355
346
|
def code_times(argument, **globals)
|
356
347
|
raw.times do |element|
|
357
348
|
argument.call(
|
358
|
-
arguments:
|
349
|
+
arguments: List.new([Integer.new(element), self]),
|
359
350
|
**globals
|
360
351
|
)
|
361
352
|
end
|
@@ -364,7 +355,7 @@ class Code
|
|
364
355
|
end
|
365
356
|
|
366
357
|
def code_truncate(n = nil)
|
367
|
-
n
|
358
|
+
n = Integer.new(0) if n.nil? || n.is_a?(Nothing)
|
368
359
|
Integer.new(raw.truncate(n.raw))
|
369
360
|
end
|
370
361
|
|
data/lib/code/object/json.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Code
|
2
4
|
class Object
|
3
5
|
class Json < Object
|
@@ -5,9 +7,15 @@ class Code
|
|
5
7
|
if json.is_an?(Object)
|
6
8
|
json
|
7
9
|
elsif json.is_a?(::Hash)
|
8
|
-
Dictionary.new(
|
10
|
+
Dictionary.new(
|
11
|
+
json.transform_keys do |key|
|
12
|
+
Json.to_code(key)
|
13
|
+
end.transform_values do |value|
|
14
|
+
Json.to_code(value)
|
15
|
+
end
|
16
|
+
)
|
9
17
|
elsif json.is_a?(::Array)
|
10
|
-
List.new(json)
|
18
|
+
List.new(json.map { |element| Json.to_code(element) })
|
11
19
|
elsif json.is_a?(::String)
|
12
20
|
String.new(json)
|
13
21
|
elsif json.is_a?(::Float)
|
data/lib/code/object/list.rb
CHANGED
@@ -4,16 +4,16 @@ class Code
|
|
4
4
|
class Object
|
5
5
|
class List < Object
|
6
6
|
def initialize(*args, **_kargs, &_block)
|
7
|
-
raw = args.first
|
7
|
+
raw = args.first
|
8
8
|
raw = raw.raw if raw.is_an?(Object)
|
9
9
|
@raw = raw.to_a
|
10
10
|
end
|
11
11
|
|
12
12
|
def call(**args)
|
13
13
|
operator = args.fetch(:operator, nil)
|
14
|
-
arguments = args.fetch(:arguments,
|
14
|
+
arguments = args.fetch(:arguments, List.new)
|
15
15
|
globals = multi_fetch(args, *GLOBALS)
|
16
|
-
value = arguments.
|
16
|
+
value = arguments.code_first
|
17
17
|
|
18
18
|
case operator.to_s
|
19
19
|
when "sort"
|
@@ -83,8 +83,11 @@ class Code
|
|
83
83
|
|
84
84
|
def code_any?(argument, **globals)
|
85
85
|
Boolean.new(
|
86
|
-
raw.any
|
87
|
-
argument.call(
|
86
|
+
raw.any?.with_index do |element, index|
|
87
|
+
argument.call(
|
88
|
+
arguments: List.new([element, Integer.new(index), self]),
|
89
|
+
**globals
|
90
|
+
).truthy?
|
88
91
|
rescue Error::Next => e
|
89
92
|
e.value || Nothing.new
|
90
93
|
end
|
@@ -97,16 +100,22 @@ class Code
|
|
97
100
|
end
|
98
101
|
|
99
102
|
def code_detect(argument, **globals)
|
100
|
-
raw.detect do |element|
|
101
|
-
argument.call(
|
103
|
+
raw.detect.with_index do |element, index|
|
104
|
+
argument.call(
|
105
|
+
arguments: List.new([element, Integer.new(index), self]),
|
106
|
+
**globals
|
107
|
+
).truthy?
|
102
108
|
rescue Error::Next => e
|
103
109
|
e.value || Nothing.new
|
104
110
|
end || Nothing.new
|
105
111
|
end
|
106
112
|
|
107
113
|
def code_each(argument, **globals)
|
108
|
-
raw.each do |element|
|
109
|
-
argument.call(
|
114
|
+
raw.each.with_index do |element, index|
|
115
|
+
argument.call(
|
116
|
+
arguments: List.new([element, Integer.new(index), self]),
|
117
|
+
**globals
|
118
|
+
)
|
110
119
|
rescue Error::Next => e
|
111
120
|
e.value || Nothing.new
|
112
121
|
end
|
@@ -118,7 +127,7 @@ class Code
|
|
118
127
|
end
|
119
128
|
|
120
129
|
def code_flatten(level = nil)
|
121
|
-
level
|
130
|
+
level = Integer.new(-1) if level.nil? || level.is_a?(Nothing)
|
122
131
|
level = level.raw if level.is_a?(Integer)
|
123
132
|
|
124
133
|
List.new(
|
@@ -148,8 +157,11 @@ class Code
|
|
148
157
|
|
149
158
|
def code_map(argument, **globals)
|
150
159
|
List.new(
|
151
|
-
raw.map do |element|
|
152
|
-
argument.call(
|
160
|
+
raw.map.with_index do |element, index|
|
161
|
+
argument.call(
|
162
|
+
arguments: List.new([element, Integer.new(index), self]),
|
163
|
+
**globals
|
164
|
+
)
|
153
165
|
rescue Error::Next => e
|
154
166
|
e.value || Nothing.new
|
155
167
|
end
|
@@ -161,8 +173,11 @@ class Code
|
|
161
173
|
end
|
162
174
|
|
163
175
|
def code_max_by(argument, **globals)
|
164
|
-
raw.max_by do |element|
|
165
|
-
argument.call(
|
176
|
+
raw.max_by.with_index do |element, index|
|
177
|
+
argument.call(
|
178
|
+
arguments: List.new([element, Integer.new(index), self]),
|
179
|
+
**globals
|
180
|
+
)
|
166
181
|
rescue Error::Next => e
|
167
182
|
e.value || Nothing.new
|
168
183
|
end || Nothing.new
|
@@ -170,8 +185,11 @@ class Code
|
|
170
185
|
|
171
186
|
def code_none?(argument, **globals)
|
172
187
|
Boolean.new(
|
173
|
-
raw.none
|
174
|
-
argument.call(
|
188
|
+
raw.none?.with_index do |element, index|
|
189
|
+
argument.call(
|
190
|
+
arguments: List.new([element, Integer.new(index), self]),
|
191
|
+
**globals
|
192
|
+
).truthy?
|
175
193
|
rescue Error::Next => e
|
176
194
|
(e.value || Nothing.new).truthy?
|
177
195
|
end
|
@@ -179,9 +197,9 @@ class Code
|
|
179
197
|
end
|
180
198
|
|
181
199
|
def code_reduce(argument, **globals)
|
182
|
-
raw.reduce do |acc, element|
|
200
|
+
raw.reduce.with_index do |acc, element, index|
|
183
201
|
argument.call(
|
184
|
-
arguments:
|
202
|
+
arguments: List.new([acc, element, Integer.new(index), self]),
|
185
203
|
**globals
|
186
204
|
)
|
187
205
|
rescue Error::Next => e
|
@@ -195,8 +213,11 @@ class Code
|
|
195
213
|
|
196
214
|
def code_select(argument, **globals)
|
197
215
|
List.new(
|
198
|
-
raw.select do |element|
|
199
|
-
argument.call(
|
216
|
+
raw.select.with_index do |element, index|
|
217
|
+
argument.call(
|
218
|
+
arguments: List.new([element, Integer.new(index), self]),
|
219
|
+
**globals
|
220
|
+
).truthy?
|
200
221
|
rescue Error::Next => e
|
201
222
|
(e.value || Nothing.new).truthy?
|
202
223
|
end
|
@@ -204,10 +225,12 @@ class Code
|
|
204
225
|
end
|
205
226
|
|
206
227
|
def code_select!(argument, **globals)
|
207
|
-
raw.select
|
208
|
-
argument.call(
|
228
|
+
raw.select!.with_index do |element, index|
|
229
|
+
argument.call(
|
230
|
+
arguments: List.new([element, Integer.new(index), self]),
|
231
|
+
**globals
|
232
|
+
).truthy?
|
209
233
|
rescue Error::Next => e
|
210
|
-
p e.value
|
211
234
|
(e.value || Nothing.new).truthy?
|
212
235
|
end
|
213
236
|
|
@@ -229,6 +252,10 @@ class Code
|
|
229
252
|
def code_sum
|
230
253
|
raw.inject(&:code_plus) || Nothing.new
|
231
254
|
end
|
255
|
+
|
256
|
+
def any?
|
257
|
+
raw.any?
|
258
|
+
end
|
232
259
|
end
|
233
260
|
end
|
234
261
|
end
|
@@ -11,16 +11,24 @@ class Code
|
|
11
11
|
String.new(raw.code_get(String.new(:name)))
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
Boolean.new(raw.code_get(String.new(:
|
14
|
+
def code_regular?
|
15
|
+
Boolean.new(raw.code_get(String.new(:regular?)))
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
Boolean.new(raw.code_get(String.new(:
|
18
|
+
def code_keyword?
|
19
|
+
Boolean.new(raw.code_get(String.new(:keyword?)))
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
Boolean.new(raw.code_get(String.new(:
|
22
|
+
def code_keyword?
|
23
|
+
Boolean.new(raw.code_get(String.new(:keyword?)))
|
24
|
+
end
|
25
|
+
|
26
|
+
def code_regular_splat?
|
27
|
+
Boolean.new(raw.code_get(String.new(:regular_splat?)))
|
28
|
+
end
|
29
|
+
|
30
|
+
def code_keyword_splat?
|
31
|
+
Boolean.new(raw.code_get(String.new(:keyword_splat?)))
|
24
32
|
end
|
25
33
|
|
26
34
|
def code_default
|
@@ -32,19 +40,19 @@ class Code
|
|
32
40
|
end
|
33
41
|
|
34
42
|
def regular?
|
35
|
-
|
43
|
+
code_regular?.truthy?
|
36
44
|
end
|
37
45
|
|
38
46
|
def keyword?
|
39
|
-
code_keyword
|
47
|
+
code_keyword?.truthy?
|
40
48
|
end
|
41
49
|
|
42
50
|
def regular_splat?
|
43
|
-
code_regular_splat
|
51
|
+
code_regular_splat?.truthy?
|
44
52
|
end
|
45
53
|
|
46
54
|
def keyword_splat?
|
47
|
-
code_keyword_splat
|
55
|
+
code_keyword_splat?.truthy?
|
48
56
|
end
|
49
57
|
end
|
50
58
|
end
|
data/lib/code/object/range.rb
CHANGED
@@ -15,9 +15,9 @@ class Code
|
|
15
15
|
|
16
16
|
def call(**args)
|
17
17
|
operator = args.fetch(:operator, nil)
|
18
|
-
arguments = args.fetch(:arguments,
|
18
|
+
arguments = args.fetch(:arguments, List.new)
|
19
19
|
globals = multi_fetch(args, *GLOBALS)
|
20
|
-
value = arguments.
|
20
|
+
value = arguments.code_first
|
21
21
|
|
22
22
|
case operator.to_s
|
23
23
|
when "all?"
|
@@ -53,24 +53,41 @@ class Code
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def code_all?(argument, **globals)
|
56
|
+
index = 0
|
56
57
|
Boolean.new(
|
57
58
|
raw.all? do |element|
|
58
|
-
argument
|
59
|
+
argument
|
60
|
+
.call(
|
61
|
+
arguments: List.new([element, Integer.new(index), self]),
|
62
|
+
**globals
|
63
|
+
)
|
64
|
+
.truthy?
|
65
|
+
.tap { index += 1 }
|
59
66
|
end
|
60
67
|
)
|
61
68
|
end
|
62
69
|
|
63
70
|
def code_any?(argument, **globals)
|
71
|
+
index = 0
|
64
72
|
Boolean.new(
|
65
73
|
raw.any? do |element|
|
66
|
-
argument
|
74
|
+
argument
|
75
|
+
.call(
|
76
|
+
arguments: List.new([element, Integer.new(index), self]),
|
77
|
+
**globals
|
78
|
+
)
|
79
|
+
.truthy?
|
80
|
+
.tap { index += 1 }
|
67
81
|
end
|
68
82
|
)
|
69
83
|
end
|
70
84
|
|
71
85
|
def code_each(argument, **globals)
|
72
|
-
raw.each do |element|
|
73
|
-
argument.call(
|
86
|
+
raw.each.with_index do |element, index|
|
87
|
+
argument.call(
|
88
|
+
arguments: List.new([element, Integer.new(index), self]),
|
89
|
+
**globals
|
90
|
+
)
|
74
91
|
end
|
75
92
|
self
|
76
93
|
end
|
@@ -85,16 +102,22 @@ class Code
|
|
85
102
|
|
86
103
|
def code_map(argument, **globals)
|
87
104
|
List.new(
|
88
|
-
raw.map do |element|
|
89
|
-
argument.call(
|
105
|
+
raw.map.with_index do |element, index|
|
106
|
+
argument.call(
|
107
|
+
arguments: List.new([element, Integer.new(index), self]),
|
108
|
+
**globals
|
109
|
+
)
|
90
110
|
end
|
91
111
|
)
|
92
112
|
end
|
93
113
|
|
94
114
|
def code_select(argument, **globals)
|
95
115
|
List.new(
|
96
|
-
raw.select do |element|
|
97
|
-
argument.call(
|
116
|
+
raw.select.with_index do |element, index|
|
117
|
+
argument.call(
|
118
|
+
arguments: List.new([element, Integer.new(index), self]),
|
119
|
+
**globals
|
120
|
+
).truthy?
|
98
121
|
end
|
99
122
|
)
|
100
123
|
end
|
data/lib/code/object/string.rb
CHANGED
@@ -11,9 +11,9 @@ class Code
|
|
11
11
|
|
12
12
|
def call(**args)
|
13
13
|
operator = args.fetch(:operator, nil)
|
14
|
-
arguments = args.fetch(:arguments,
|
14
|
+
arguments = args.fetch(:arguments, List.new)
|
15
15
|
globals = multi_fetch(args, *GLOBALS)
|
16
|
-
value = arguments.
|
16
|
+
value = arguments.code_first
|
17
17
|
|
18
18
|
case operator.to_s
|
19
19
|
when "&", "to_function"
|
data/lib/code/object/time.rb
CHANGED
@@ -47,8 +47,8 @@ class Code
|
|
47
47
|
|
48
48
|
def call(**args)
|
49
49
|
operator = args.fetch(:operator, nil)
|
50
|
-
arguments = args.fetch(:arguments,
|
51
|
-
value = arguments.
|
50
|
+
arguments = args.fetch(:arguments, List.new)
|
51
|
+
value = arguments.code_first
|
52
52
|
|
53
53
|
case operator.to_s
|
54
54
|
when "after?"
|
@@ -69,12 +69,12 @@ class Code
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def code_after?(other = nil)
|
72
|
-
other
|
72
|
+
other = Time.code_now if other.nil? || other.is_a?(Nothing)
|
73
73
|
Boolean.new(raw.after?(other.raw))
|
74
74
|
end
|
75
75
|
|
76
76
|
def code_before?(other = nil)
|
77
|
-
other
|
77
|
+
other = Time.code_now if other.nil? || other.is_a?(Nothing)
|
78
78
|
Boolean.new(raw.before?(other.raw))
|
79
79
|
end
|
80
80
|
|