code-ruby 1.2.7 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d0298c4fcdefba32c3bad640c7d226c7762927d798c13ccd9ee8f3b9435b018
4
- data.tar.gz: 231ce8a3d7f87818e52ad35285666fba86722768aae493456b5dc16beea9c31b
3
+ metadata.gz: e36d2ab574e54db93b35370cc0dec2021a518e595ae05d38a4775b39e23a663d
4
+ data.tar.gz: 34f7b0587badd6faffbde82b8ebb85ae1bbec7ad1254b20de18c3f6bf6745d30
5
5
  SHA512:
6
- metadata.gz: a6596a13b6c128a6a8c7cefd0896e6057a88e307c300a1ef7e60a6ceb3df4ab20aa80bac2dcc8b31ef395db8a74b145cc78dae800cf6bbbf60dc0e6e319c9434
7
- data.tar.gz: 9936cc6041d343ee2a2c1a6a4f488aa3666ec2738609e20639e56f0b093bf49a22dcff93dba7fd5ff645c689892bb5d12ea43a60762977cf69f41d85671c1ebe
6
+ metadata.gz: 669c6eeeea9097a0b9606571739580ed78bd57fe146c5b59495bb648f04acd919329d8837eebdc1211d46d8a1a2b6c1f5fc57035c854590239933f7d9079271a
7
+ data.tar.gz: 42321fcb6e6b3201e44d3a270752c43362cfca512668d7f937384a91aa880ffa68d2836a3dcdb2736b9263419f53b4fb756e37bb48f5b6a66be8bd3cd5b1f0be
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.2.7)
4
+ code-ruby (1.3.0)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/TODO ADDED
@@ -0,0 +1,219 @@
1
+ to_query
2
+ to_h
3
+ include?
4
+ &
5
+ shelljoin
6
+ *
7
+ +
8
+ blank?
9
+ -
10
+ present?
11
+ from
12
+ extract!
13
+ at
14
+ fetch
15
+ union
16
+ difference
17
+ intersection
18
+ intersect?
19
+ push
20
+ append
21
+ pop
22
+ shift
23
+ unshift
24
+ each_index
25
+ join
26
+ rotate
27
+ rotate!
28
+ sort!
29
+ sort_by!
30
+ collect!
31
+ map!
32
+ select!
33
+ filter!
34
+ keep_if
35
+ values_at
36
+ sort
37
+ delete_if
38
+ reject!
39
+ delete_at
40
+ count
41
+ fill
42
+ find_index
43
+ rassoc
44
+ select
45
+ filter
46
+ uniq!
47
+ reject
48
+ collect
49
+ map
50
+ compact!
51
+ assoc
52
+ flatten!
53
+ permutation
54
+ transpose
55
+ flatten
56
+ repeated_combination
57
+ product
58
+ combination
59
+ repeated_permutation
60
+ any?
61
+ all?
62
+ minmax
63
+ bsearch_index
64
+ none?
65
+ one?
66
+ bsearch
67
+ reverse_each
68
+ deconstruct
69
+ |
70
+ first
71
+ zip
72
+ take
73
+ take_while
74
+ drop
75
+ drop_while
76
+ cycle
77
+ shuffle!
78
+ shuffle
79
+ sample
80
+ <=>
81
+ <<
82
+ sum
83
+ uniq
84
+ compact
85
+ ==
86
+ second
87
+ pack
88
+ to
89
+ []
90
+ []=
91
+ empty?
92
+ eql?
93
+ insert
94
+ compact_blank!
95
+ index
96
+ rindex
97
+ replace
98
+ clear
99
+ max
100
+ min
101
+ hash
102
+ inspect
103
+ including
104
+ excluding
105
+ length
106
+ size
107
+ third
108
+ without
109
+ each
110
+ fourth
111
+ fifth
112
+ forty_two
113
+ third_to_last
114
+ second_to_last
115
+ extract_options!
116
+ in_groups_of
117
+ reverse
118
+ to_ary
119
+ concat
120
+ prepend
121
+ reverse!
122
+ in_groups
123
+ to_a
124
+ to_s
125
+ split
126
+ inquiry
127
+ to_sentence
128
+ as_json
129
+ pretty_print
130
+ delete
131
+ to_formatted_s
132
+ pretty_print_cycle
133
+ to_xml
134
+ to_fs
135
+ slice
136
+ slice!
137
+ dig
138
+ to_json
139
+ chunk
140
+ slice_before
141
+ slice_after
142
+ slice_when
143
+ chunk_while
144
+ maximum
145
+ chain
146
+ to_set
147
+ lazy
148
+ many?
149
+ sole
150
+ exclude?
151
+ minimum
152
+ pick
153
+ index_by
154
+ index_with
155
+ pluck
156
+ in_order_of
157
+ compact_blank
158
+ find
159
+ entries
160
+ sort_by
161
+ grep
162
+ grep_v
163
+ detect
164
+ find_all
165
+ filter_map
166
+ flat_map
167
+ collect_concat
168
+ inject
169
+ reduce
170
+ partition
171
+ group_by
172
+ tally
173
+ min_by
174
+ max_by
175
+ minmax_by
176
+ member?
177
+ each_with_index
178
+ each_entry
179
+ each_slice
180
+ each_cons
181
+ each_with_object
182
+ to_yaml
183
+ duplicable?
184
+ in?
185
+ with
186
+ presence_in
187
+ presence
188
+ acts_like?
189
+ html_safe?
190
+ with_options
191
+ try!
192
+ try
193
+ pretty_print_inspect
194
+ singleton_class
195
+ dup
196
+ itself
197
+ kind_of?
198
+ is_a?
199
+ display
200
+ class_eval
201
+ extend
202
+ clone
203
+ frozen?
204
+ then
205
+ tap
206
+ yield_self
207
+ ===
208
+ class
209
+ !~
210
+ nil?
211
+ respond_to?
212
+ freeze
213
+ object_id
214
+ to_enum
215
+ enum_for
216
+ pretty_inspect
217
+ equal?
218
+ !
219
+ !=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.7
1
+ 1.3.0
@@ -0,0 +1,418 @@
1
+ class Code
2
+ module Concerns
3
+ module Shared
4
+ attr_reader :raw
5
+
6
+ def call(**args)
7
+ code_operator = args.fetch(:operator, nil).to_code
8
+ code_arguments = args.fetch(:arguments, []).to_code
9
+ code_value = code_arguments.code_first
10
+
11
+ case code_operator.to_s
12
+ when "new"
13
+ sig(args) { Object.repeat }
14
+ code_new(*code_arguments.raw)
15
+ when "!", "not"
16
+ sig(args)
17
+ code_exclamation_point
18
+ when "!=", "different"
19
+ sig(args) { Object }
20
+ code_different(code_value)
21
+ when "&&", "and"
22
+ sig(args) { Object }
23
+ code_and(code_value)
24
+ when "+", "self"
25
+ sig(args)
26
+ code_self
27
+ when "..", "inclusive_range"
28
+ sig(args) { Object }
29
+ code_inclusive_range(code_value)
30
+ when "...", "exclusive_range"
31
+ sig(args) { Object }
32
+ code_exclusive_range(code_value)
33
+ when "==", "equal"
34
+ sig(args) { Object }
35
+ code_equal_equal(code_value)
36
+ when "===", "strict_equal"
37
+ sig(args) { Object }
38
+ code_equal_equal_equal(code_value)
39
+ when "falsy?"
40
+ sig(args)
41
+ code_falsy?
42
+ when "truthy?"
43
+ sig(args)
44
+ code_truthy?
45
+ when "||", "or"
46
+ sig(args) { Object }
47
+ code_or(code_value)
48
+ when "to_boolean"
49
+ sig(args)
50
+ code_to_boolean
51
+ when "to_class"
52
+ sig(args)
53
+ code_to_class
54
+ when "to_date"
55
+ sig(args)
56
+ code_to_date
57
+ when "to_decimal"
58
+ sig(args)
59
+ code_to_decimal
60
+ when "to_dictionary"
61
+ sig(args)
62
+ code_to_dictionary
63
+ when "to_duration"
64
+ sig(args)
65
+ code_to_duration
66
+ when "to_integer"
67
+ sig(args)
68
+ code_to_integer
69
+ when "to_list"
70
+ sig(args)
71
+ code_to_list
72
+ when "to_nothing"
73
+ sig(args)
74
+ code_to_nothing
75
+ when "to_range"
76
+ sig(args)
77
+ code_to_range
78
+ when "to_string"
79
+ sig(args)
80
+ code_to_string
81
+ when "to_time"
82
+ sig(args)
83
+ code_to_time
84
+ when "as_json"
85
+ sig(args)
86
+ code_as_json
87
+ when "duplicate"
88
+ sig(args)
89
+ code_duplicate
90
+ when "deep_duplicate"
91
+ sig(args)
92
+ code_deep_duplicate
93
+ when "to_parameter"
94
+ sig(args)
95
+ code_to_parameter
96
+ when "to_json"
97
+ sig(args) { { pretty: Object::Boolean.maybe } }
98
+
99
+ if code_arguments.any?
100
+ code_to_json(pretty: code_value.code_get(:pretty))
101
+ else
102
+ code_to_json
103
+ end
104
+ when "name"
105
+ sig(args)
106
+ code_name
107
+ when /=$/
108
+ sig(args) { Object }
109
+
110
+ if code_operator.to_s == "="
111
+ code_context = args.fetch(:context)
112
+ code_context.code_set(self, code_value)
113
+ else
114
+ code_context = args.fetch(:context).code_lookup!(self)
115
+ code_context.code_set(
116
+ self,
117
+ code_context.code_fetch(self).call(
118
+ **args,
119
+ operator: code_operator.to_s.chop,
120
+ arguments: Object::List.new([code_value])
121
+ )
122
+ )
123
+ end
124
+
125
+ code_context.code_fetch(self)
126
+ else
127
+ raise(Error, "#{code_operator.inspect} not defined on #{code_inspect}:#{code_name}")
128
+ end
129
+ end
130
+
131
+ def <=>(other)
132
+ code_other = other.to_code
133
+
134
+ [raw, self.class] <=> [code_other.raw, code_other.class]
135
+ end
136
+
137
+ def ==(other)
138
+ code_other = other.to_code
139
+
140
+ [raw, self.class] == [code_other.raw, code_other.class]
141
+ end
142
+
143
+ def eql?(other)
144
+ code_other = other.to_code
145
+
146
+ [raw, self.class].eql?([code_other.raw, code_other.class])
147
+ end
148
+
149
+ def code_and(other)
150
+ code_other = other.to_code
151
+
152
+ truthy? ? code_other : self
153
+ end
154
+
155
+ def code_different(other)
156
+ code_other = other.to_code
157
+
158
+ Object::Boolean.new(self != code_other)
159
+ end
160
+
161
+ def code_equal_equal(other)
162
+ code_other = other.to_code
163
+
164
+ Object::Boolean.new(self == code_other)
165
+ end
166
+
167
+ def code_exclamation_point
168
+ Object::Boolean.new(falsy?)
169
+ end
170
+
171
+ def code_exclusive_range(value)
172
+ code_value = value.to_code
173
+
174
+ Object::Range.new(self, code_value, exclude_end: true)
175
+ end
176
+
177
+ def code_inclusive_range(value)
178
+ code_value = value.to_code
179
+
180
+ Object::Range.new(self, code_value, exclude_end: false)
181
+ end
182
+
183
+ def code_or(other)
184
+ code_other = other.to_code
185
+
186
+ truthy? ? self : code_other
187
+ end
188
+
189
+ def code_self
190
+ self
191
+ end
192
+
193
+ def code_equal_equal_equal(other)
194
+ code_other = other.to_code
195
+
196
+ Object::Boolean.new(self === code_other)
197
+ end
198
+
199
+ def falsy?
200
+ !truthy?
201
+ end
202
+
203
+ def hash
204
+ [self.class, raw].hash
205
+ end
206
+
207
+ def multi_fetch(hash, *keys)
208
+ keys.to_h { |key| [key, hash.fetch(key)] }
209
+ end
210
+
211
+ def sig(args, &)
212
+ Type::Sig.sig(args, object: self, &)
213
+
214
+ Object::Nothing.new
215
+ end
216
+
217
+ def truthy?
218
+ true
219
+ end
220
+
221
+ def to_json(...)
222
+ as_json(...).to_json(...)
223
+ end
224
+
225
+ def as_json(...)
226
+ raw.as_json(...)
227
+ end
228
+
229
+ def code_to_json(pretty: nil)
230
+ if Object::Boolean.new(pretty).truthy?
231
+ Object::String.new(::JSON.pretty_generate(self))
232
+ else
233
+ Object::String.new(to_json)
234
+ end
235
+ end
236
+
237
+ def code_as_json
238
+ as_json.to_code
239
+ end
240
+
241
+ def to_code
242
+ self
243
+ end
244
+
245
+ def succ
246
+ self.class.new(raw.succ)
247
+ end
248
+
249
+ def code_duplicate
250
+ self.class.new(self)
251
+ end
252
+
253
+ def code_deep_duplicate
254
+ self.class.new(self)
255
+ end
256
+
257
+ def self.code_fetch(...)
258
+ Object::Nothing.new
259
+ end
260
+
261
+ def self.code_set(...)
262
+ Object::Nothing.new
263
+ end
264
+
265
+ def self.code_get(...)
266
+ Object::Nothing.new
267
+ end
268
+
269
+ def code_fetch(...)
270
+ Object::Nothing.new
271
+ end
272
+
273
+ def code_set(...)
274
+ Object::Nothing.new
275
+ end
276
+
277
+ def code_get(...)
278
+ Object::Nothing.new
279
+ end
280
+
281
+ def code_to_parameter
282
+ code_to_string.code_parameterize
283
+ end
284
+
285
+ def code_falsy?
286
+ Object::Boolean.new(falsy?)
287
+ end
288
+
289
+ def code_truthy?
290
+ Object::Boolean.new(truthy?)
291
+ end
292
+
293
+ def code_to_boolean
294
+ Object::Boolean.new(self)
295
+ end
296
+
297
+ def code_to_class
298
+ Object::Class.new(self)
299
+ end
300
+
301
+ def code_to_date
302
+ Object::Date.new(self)
303
+ end
304
+
305
+ def code_to_decimal
306
+ Object::Decimal.new(self)
307
+ end
308
+
309
+ def code_to_dictionary
310
+ Object::Dictionary.new(self)
311
+ end
312
+
313
+ def code_to_duration
314
+ Object::Duration.new(self)
315
+ end
316
+
317
+ def code_to_integer
318
+ Object::Integer.new(self)
319
+ end
320
+
321
+ def code_to_list
322
+ Object::List.new(self)
323
+ end
324
+
325
+ def code_to_nothing
326
+ Object::Nothing.new(self)
327
+ end
328
+
329
+ def code_to_range
330
+ Object::Range.new(self)
331
+ end
332
+
333
+ def code_to_string
334
+ Object::String.new(self)
335
+ end
336
+
337
+ def code_to_time
338
+ Object::Time.new(self)
339
+ end
340
+
341
+ def to_s
342
+ code_to_string.raw
343
+ end
344
+
345
+ def inspect
346
+ code_inspect.raw
347
+ end
348
+
349
+ def nothing?
350
+ false
351
+ end
352
+
353
+ def code_falsy?
354
+ Object::Boolean.new(falsy?)
355
+ end
356
+
357
+ def code_truthy?
358
+ Object::Boolean.new(truthy?)
359
+ end
360
+
361
+ def code_to_boolean
362
+ Object::Boolean.new(self)
363
+ end
364
+
365
+ def code_to_class
366
+ Object::Class.new(self)
367
+ end
368
+
369
+ def code_to_date
370
+ Object::Date.new(self)
371
+ end
372
+
373
+ def code_to_decimal
374
+ Object::Decimal.new(self)
375
+ end
376
+
377
+ def code_to_dictionary
378
+ Object::Dictionary.new(self)
379
+ end
380
+
381
+ def code_to_duration
382
+ Object::Duration.new(self)
383
+ end
384
+
385
+ def code_to_integer
386
+ Object::Integer.new(self)
387
+ end
388
+
389
+ def code_to_list
390
+ Object::List.new(self)
391
+ end
392
+
393
+ def code_to_nothing
394
+ Object::Nothing.new(self)
395
+ end
396
+
397
+ def code_to_range
398
+ Object::Range.new(self)
399
+ end
400
+
401
+ def code_to_string
402
+ Object::String.new(self)
403
+ end
404
+
405
+ def code_to_time
406
+ Object::Time.new(self)
407
+ end
408
+
409
+ def code_inspect
410
+ code_to_string
411
+ end
412
+
413
+ def code_name
414
+ Object::String.new(name)
415
+ end
416
+ end
417
+ end
418
+ end
@@ -0,0 +1,4 @@
1
+ class Code
2
+ module Concerns
3
+ end
4
+ end
@@ -659,6 +659,12 @@ class Code
659
659
  def code_values
660
660
  List.new(raw.values)
661
661
  end
662
+
663
+ def code_deep_duplicate
664
+ Dictionary.new(
665
+ raw.dup.to_h { |key, value| [key, value].map(&:code_deep_duplicate) }
666
+ )
667
+ end
662
668
  end
663
669
  end
664
670
  end
@@ -436,12 +436,29 @@ class Code
436
436
  raw.inject(&:code_plus) || Nothing.new
437
437
  end
438
438
 
439
+ def code_deep_duplicate
440
+ List.new(raw.dup.map { |element| element.code_deep_duplicate })
441
+ end
442
+
439
443
  def code_get(argument)
440
444
  code_argument = argument.to_code
441
445
 
442
446
  raw[code_argument] || Nothing.new
443
447
  end
444
448
 
449
+ def code_set(key, value)
450
+ code_key = key.to_code.code_to_integer
451
+ code_value = value.to_code
452
+ raw[code_key.raw] = code_value
453
+ code_value
454
+ end
455
+
456
+ def code_fetch(key)
457
+ code_key = key.to_code.code_to_integer
458
+
459
+ raw.fetch(code_key.raw, Nothing.new)
460
+ end
461
+
445
462
  def any?
446
463
  code_any?.truthy?
447
464
  end
@@ -14,6 +14,14 @@ class Code
14
14
  def nothing?
15
15
  true
16
16
  end
17
+
18
+ def code_to_string
19
+ String.new
20
+ end
21
+
22
+ def code_inspect
23
+ String.new("nothing")
24
+ end
17
25
  end
18
26
  end
19
27
  end
@@ -4,9 +4,17 @@ class Code
4
4
  class Object
5
5
  class String < Object
6
6
  def initialize(*args, **_kargs, &)
7
- raw = args.first || Nothing.new
8
- raw = raw.raw if raw.is_a?(Object)
9
- @raw = raw.to_s
7
+ if args.first.is_an?(Class)
8
+ @raw = args.first.raw.name
9
+ elsif args.first.is_an?(Object)
10
+ @raw = args.first.raw.to_s
11
+ elsif args.first.is_a?(::Class)
12
+ @raw = args.first.name
13
+ elsif args.first
14
+ @raw = args.first.to_s
15
+ else
16
+ @raw = ""
17
+ end
10
18
  end
11
19
 
12
20
  def call(**args)
@@ -37,6 +45,9 @@ class Code
37
45
  when "reverse"
38
46
  sig(args)
39
47
  code_reverse
48
+ when "parameterize"
49
+ sig(args)
50
+ code_parameterize
40
51
  else
41
52
  super
42
53
  end
@@ -69,6 +80,14 @@ class Code
69
80
  Function.new([{ name: "_" }], "_.#{raw}")
70
81
  end
71
82
 
83
+ def code_inspect
84
+ String.new(raw.inspect)
85
+ end
86
+
87
+ def code_parameterize
88
+ String.new(raw.parameterize)
89
+ end
90
+
72
91
  def code_first(n = nil)
73
92
  code_n = n.to_code
74
93
  code_n = Integer.new(1) if code_n.nothing?
data/lib/code/object.rb CHANGED
@@ -12,21 +12,12 @@ class Code
12
12
  ::BigDecimal
13
13
  ].freeze
14
14
 
15
- attr_reader :raw
16
-
17
- delegate :to_s, :inspect, to: :raw
15
+ include Concerns::Shared
16
+ extend Concerns::Shared
18
17
 
19
18
  def initialize(...)
20
19
  end
21
20
 
22
- def self.nothing?
23
- false
24
- end
25
-
26
- def nothing?
27
- false
28
- end
29
-
30
21
  def self.maybe
31
22
  Type::Maybe.new(self)
32
23
  end
@@ -39,445 +30,20 @@ class Code
39
30
  Type::Or.new(self, other)
40
31
  end
41
32
 
42
- def self.call(**args)
43
- code_operator = args.fetch(:operator, nil).to_code
44
- code_arguments = args.fetch(:arguments, []).to_code
45
- code_value = code_arguments.code_first
46
-
47
- case code_operator.to_s
48
- when "new"
49
- sig(args) { Object.repeat }
50
- code_new(*code_arguments.raw)
51
- when "!", "not"
52
- sig(args)
53
- code_exclamation_point
54
- when "!=", "different"
55
- sig(args) { Object }
56
- code_different(code_value)
57
- when "&&", "and"
58
- sig(args) { Object }
59
- code_and_operator(code_value)
60
- when "+", "self"
61
- sig(args)
62
- code_self
63
- when "..", "inclusive_range"
64
- sig(args) { Object }
65
- code_inclusive_range(code_value)
66
- when "...", "exclusive_range"
67
- sig(args) { Object }
68
- code_exclusive_range(code_value)
69
- when "==", "equal"
70
- sig(args) { Object }
71
- code_equal_equal(code_value)
72
- when "===", "strict_equal"
73
- sig(args) { Object }
74
- code_equal_equal_equal(code_value)
75
- when "falsy?"
76
- sig(args)
77
- Boolean.new(falsy?)
78
- when "truthy?"
79
- sig(args)
80
- Boolean.new(truthy?)
81
- when "||", "or"
82
- sig(args) { Object }
83
- code_or_operator(code_value)
84
- when "to_boolean"
85
- sig(args)
86
- Boolean.new(self)
87
- when "to_class"
88
- sig(args)
89
- Class.new(self)
90
- when "to_date"
91
- sig(args)
92
- Date.new(self)
93
- when "to_decimal"
94
- sig(args)
95
- Decimal.new(self)
96
- when "to_dictionary"
97
- sig(args)
98
- Dictionary.new(self)
99
- when "to_duration"
100
- sig(args)
101
- Duration.new(self)
102
- when "to_integer"
103
- sig(args)
104
- Integer.new(self)
105
- when "to_list"
106
- sig(args)
107
- List.new(self)
108
- when "to_nothing"
109
- sig(args)
110
- Nothing.new(self)
111
- when "to_range"
112
- sig(args)
113
- Range.new(self)
114
- when "to_string"
115
- sig(args)
116
- String.new(self)
117
- when "to_time"
118
- sig(args)
119
- Time.new(self)
120
- when "as_json"
121
- sig(args)
122
- code_as_json
123
- when "to_json"
124
- sig(args) { { pretty: Boolean.maybe } }
125
-
126
- if code_arguments.any?
127
- code_to_json(pretty: code_value.code_get(:pretty))
128
- else
129
- code_to_json
130
- end
131
- when /=$/
132
- sig(args) { Object }
133
-
134
- if code_operator.to_s == "="
135
- code_context = args.fetch(:context)
136
- code_context.code_set(self, value)
137
- else
138
- code_context = args.fetch(:context).code_lookup!(self)
139
- code_context.code_set(
140
- self,
141
- code_context.code_fetch(self).call(
142
- **args,
143
- operator: operator.to_s.chop,
144
- arguments: List.new([code_value])
145
- )
146
- )
147
- end
148
-
149
- context.code_fetch(self)
150
- else
151
- raise(Error, "#{code_operator.inspect} not defined on #{inspect}:Class")
152
- end
153
- end
154
-
155
- def self.code_new(*arguments)
156
- code_arguments = arguments.to_code
157
-
158
- new(*code_arguments.raw)
159
- end
160
-
161
- def self.code_and_operator(other)
162
- code_other = other.to_code
163
-
164
- truthy? ? code_other : self
165
- end
166
-
167
- def self.code_different(other)
168
- code_other = other.to_code
169
-
170
- Boolean.new(self != code_other)
171
- end
172
-
173
- def self.code_equal_equal(other)
174
- code_other = other.to_code
175
-
176
- Boolean.new(self == code_other)
177
- end
178
-
179
- def self.code_exclamation_point
180
- Boolean.new(falsy?)
181
- end
182
-
183
- def self.code_exclusive_range(value)
184
- code_value = value.to_code
185
-
186
- Range.new(self, code_value, exclude_end: true)
187
- end
188
-
189
- def self.code_inclusive_range(value)
190
- code_value = value.to_code
191
-
192
- Range.new(self, code_value, exclude_end: false)
193
- end
194
-
195
- def self.code_or_operator(other)
196
- code_other = other.to_code
197
-
198
- truthy? ? self : code_other
199
- end
200
-
201
- def self.code_self
202
- self
203
- end
204
-
205
- def self.code_equal_equal_equal(other)
206
- code_other = other.to_code
207
-
208
- Boolean.new(self === code_other)
209
- end
210
-
211
- def self.falsy?
212
- !truthy?
213
- end
214
-
215
- def self.multi_fetch(hash, *keys)
216
- keys.to_h { |key| [key, hash.fetch(key)] }
217
- end
218
-
219
- def self.sig(args, &)
220
- Type::Sig.sig(args, object: self, &)
221
-
222
- Nothing.new
223
- end
224
-
225
- def self.to_s
226
- name
227
- end
228
-
229
- def self.inspect
230
- name
231
- end
232
-
233
- def self.truthy?
234
- true
235
- end
236
-
237
- def self.to_json(...)
238
- as_json(...).to_json(...)
239
- end
240
-
241
- def self.as_json(...)
242
- name.as_json(...)
243
- end
244
-
245
- def self.code_to_json(pretty: nil)
246
- if Boolean.new(pretty).truthy?
247
- String.new(::JSON.pretty_generate(self))
248
- else
249
- String.new(to_json)
250
- end
251
- end
252
-
253
- def self.code_as_json
254
- to_ruby.as_json.to_code
255
- end
256
-
257
- def <=>(other)
258
- code_other = other.to_code
259
-
260
- raw <=> code_other.raw
261
- end
262
-
263
- def ==(other)
264
- code_other = other.to_code
265
-
266
- raw == code_other.raw
267
- end
268
- alias eql? ==
269
-
270
- def call(**args)
271
- code_operator = args.fetch(:operator, nil).to_code
272
- code_arguments = args.fetch(:arguments, []).to_code
273
- code_value = code_arguments.code_first
274
-
275
- case code_operator.to_s
276
- when "!", "not"
277
- sig(args)
278
- code_exclamation_point
279
- when "!=", "different"
280
- sig(args) { Object }
281
- code_different(code_value)
282
- when "&&", "and"
283
- sig(args) { Object }
284
- code_and_operator(code_value)
285
- when "+", "self"
286
- sig(args)
287
- code_self
288
- when "..", "inclusive_range"
289
- sig(args) { Object }
290
- code_inclusive_range(code_value)
291
- when "...", "exclusive_range"
292
- sig(args) { Object }
293
- code_exclusive_range(code_value)
294
- when "==", "equal"
295
- sig(args) { Object }
296
- code_equal_equal(code_value)
297
- when "===", "strict_equal"
298
- sig(args) { Object }
299
- code_equal_equal_equal(code_value)
300
- when "falsy?"
301
- sig(args)
302
- Boolean.new(falsy?)
303
- when "truthy?"
304
- sig(args)
305
- Boolean.new(truthy?)
306
- when "||", "or"
307
- sig(args) { Object }
308
- code_or_operator(code_value)
309
- when "to_boolean"
310
- sig(args)
311
- Boolean.new(self)
312
- when "to_class"
313
- sig(args)
314
- Class.new(self)
315
- when "to_date"
316
- sig(args)
317
- Date.new(self)
318
- when "to_decimal"
319
- sig(args)
320
- Decimal.new(self)
321
- when "to_duration"
322
- sig(args)
323
- Duration.new(self)
324
- when "to_dictionary"
325
- sig(args)
326
- Dictionary.new(self)
327
- when "to_integer"
328
- sig(args)
329
- Integer.new(self)
330
- when "to_list"
331
- sig(args)
332
- List.new(self)
333
- when "to_nothing"
334
- sig(args)
335
- Nothing.new(self)
336
- when "to_range"
337
- sig(args)
338
- Range.new(self)
339
- when "to_string"
340
- sig(args)
341
- String.new(self)
342
- when "to_time"
343
- sig(args)
344
- Time.new(self)
345
- when "as_json"
346
- sig(args)
347
- code_as_json
348
- when "to_json"
349
- sig(args) { { pretty: Boolean.maybe } }
350
-
351
- if code_arguments.any?
352
- code_to_json(pretty: code_value.code_get(:pretty))
353
- else
354
- code_to_json
355
- end
356
- when /=$/
357
- sig(args) { Object }
358
-
359
- if code_operator.to_s == "="
360
- code_context = args.fetch(:context)
361
- code_context.code_set(self, code_value)
362
- else
363
- code_context = args.fetch(:context).code_lookup!(self)
364
- code_context.code_set(
365
- self,
366
- code_context.code_fetch(self).call(
367
- **args,
368
- operator: code_operator.to_s.chop,
369
- arguments: List.new([code_value])
370
- )
371
- )
372
- end
373
-
374
- code_context.code_fetch(self)
375
- else
376
- raise(
377
- Error,
378
- "#{code_operator.inspect} not defined on #{inspect}:#{self.class.name}"
379
- )
380
- end
381
- end
382
-
383
- def code_and_operator(other)
384
- code_other = other.to_code
385
-
386
- truthy? ? code_other : self
387
- end
388
-
389
- def code_different(other)
390
- code_other = other.to_code
391
-
392
- Boolean.new(self != code_other)
393
- end
394
-
395
- def code_equal_equal(other)
396
- code_other = other.to_code
397
-
398
- Boolean.new(self == code_other)
399
- end
400
-
401
- def code_exclamation_point
402
- Boolean.new(falsy?)
403
- end
404
-
405
- def code_exclusive_range(value)
406
- code_value = value.to_code
407
-
408
- Range.new(self, code_value, exclude_end: true)
409
- end
410
-
411
- def code_inclusive_range(value)
412
- code_value = value.to_code
413
-
414
- Range.new(self, code_value, exclude_end: false)
415
- end
416
-
417
- def code_or_operator(other)
418
- code_other = other.to_code
419
-
420
- truthy? ? self : code_other
421
- end
422
-
423
- def code_self
424
- self
425
- end
426
-
427
- def code_equal_equal_equal(other)
428
- code_other = other.to_code
429
-
430
- Boolean.new(self === code_other)
431
- end
432
-
433
- def falsy?
434
- !truthy?
435
- end
436
-
437
- def hash
438
- [self.class, raw].hash
439
- end
440
-
441
- def multi_fetch(hash, *keys)
442
- keys.to_h { |key| [key, hash.fetch(key)] }
443
- end
444
-
445
- def sig(args, &)
446
- Type::Sig.sig(args, object: self, &)
447
-
448
- Nothing.new
449
- end
450
-
451
- def truthy?
452
- true
453
- end
454
-
455
- def to_json(...)
456
- as_json(...).to_json(...)
457
- end
458
-
459
- def as_json(...)
460
- raw.as_json(...)
461
- end
462
-
463
- def code_to_json(pretty: nil)
464
- if Boolean.new(pretty).truthy?
465
- String.new(::JSON.pretty_generate(self))
466
- else
467
- String.new(to_json)
468
- end
33
+ def self.name
34
+ super.split("::")[2..].join("::")
469
35
  end
470
36
 
471
- def code_as_json
472
- as_json.to_code
37
+ def self.code_new(*args)
38
+ new(*args)
473
39
  end
474
40
 
475
- def to_code
476
- self
41
+ def name
42
+ self.class.name
477
43
  end
478
44
 
479
- def succ
480
- self.class.new(raw.succ)
45
+ def code_new(*args)
46
+ self.class.code_new(**args)
481
47
  end
482
48
  end
483
49
  end
data/lib/code-ruby.rb CHANGED
@@ -72,6 +72,18 @@ class Object
72
72
  end
73
73
  end
74
74
 
75
+ class Class
76
+ def to_code
77
+ Code::Object::Class.new(self)
78
+ end
79
+ end
80
+
81
+ class Module
82
+ def to_code
83
+ Code::Object::Class.new(self)
84
+ end
85
+ end
86
+
75
87
  class NilClass
76
88
  def to_code
77
89
  Code::Object::Nothing.new(self)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-25 00:00:00.000000000 Z
10
+ date: 2025-03-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -185,6 +185,7 @@ files:
185
185
  - LICENSE
186
186
  - README.md
187
187
  - Rakefile
188
+ - TODO
188
189
  - VERSION
189
190
  - bin/bundle
190
191
  - bin/bundle-audit
@@ -198,6 +199,8 @@ files:
198
199
  - code-ruby.gemspec
199
200
  - lib/code-ruby.rb
200
201
  - lib/code.rb
202
+ - lib/code/concerns.rb
203
+ - lib/code/concerns/shared.rb
201
204
  - lib/code/error.rb
202
205
  - lib/code/node.rb
203
206
  - lib/code/node/base_10.rb