code-ruby 3.1.2 → 4.0.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/VERSION +1 -1
- data/bin/code +100 -20
- data/lib/code/concerns/shared.rb +335 -15
- data/lib/code/format.rb +33 -15
- data/lib/code/network.rb +82 -0
- data/lib/code/node/call.rb +80 -2
- data/lib/code/node/call_argument.rb +14 -0
- data/lib/code/node/code.rb +4 -3
- data/lib/code/node/function_parameter.rb +7 -4
- data/lib/code/node/list.rb +32 -2
- data/lib/code/node/square_bracket.rb +4 -2
- data/lib/code/object/base_64.rb +132 -6
- data/lib/code/object/boolean.rb +56 -0
- data/lib/code/object/class.rb +143 -2
- data/lib/code/object/code.rb +108 -7
- data/lib/code/object/context.rb +59 -1
- data/lib/code/object/cryptography.rb +69 -0
- data/lib/code/object/date.rb +13800 -462
- data/lib/code/object/decimal.rb +1098 -0
- data/lib/code/object/dictionary.rb +1861 -11
- data/lib/code/object/duration.rb +24 -0
- data/lib/code/object/function.rb +289 -27
- data/lib/code/object/global.rb +447 -1
- data/lib/code/object/html.rb +181 -7
- data/lib/code/object/http.rb +253 -17
- data/lib/code/object/ics.rb +76 -13
- data/lib/code/object/identifier_list.rb +30 -10
- data/lib/code/object/integer.rb +1265 -2
- data/lib/code/object/json.rb +80 -1
- data/lib/code/object/list.rb +3371 -10
- data/lib/code/object/nothing.rb +53 -0
- data/lib/code/object/number.rb +120 -0
- data/lib/code/object/parameter.rb +149 -0
- data/lib/code/object/range.rb +530 -14
- data/lib/code/object/smtp.rb +103 -12
- data/lib/code/object/string.rb +968 -3
- data/lib/code/object/super.rb +11 -1
- data/lib/code/object/time.rb +13932 -498
- data/lib/code/object/url.rb +67 -0
- data/lib/code/object.rb +582 -0
- data/lib/code/parser.rb +194 -55
- data/lib/code-ruby.rb +3 -0
- data/lib/code.rb +30 -3
- metadata +135 -84
- data/.github/dependabot.yml +0 -15
- data/.github/workflows/ci.yml +0 -38
- data/.gitignore +0 -30
- data/.node-version +0 -1
- data/.npm-version +0 -1
- data/.prettierignore +0 -2
- data/.rspec +0 -1
- data/.rubocop.yml +0 -140
- data/.ruby-version +0 -1
- data/.tool-versions +0 -3
- data/AGENTS.md +0 -43
- data/Gemfile +0 -22
- data/Gemfile.lock +0 -292
- data/Rakefile +0 -5
- data/bin/bundle +0 -123
- data/bin/bundle-audit +0 -31
- data/bin/bundler-audit +0 -31
- data/bin/dorian +0 -31
- data/bin/rspec +0 -31
- data/bin/rubocop +0 -31
- data/bin/test +0 -5
- data/code-ruby.gemspec +0 -34
- data/docs/precedence.txt +0 -36
- data/package-lock.json +0 -14
- data/package.json +0 -7
- data/spec/bin/code_spec.rb +0 -48
- data/spec/code/format_spec.rb +0 -153
- data/spec/code/node/call_spec.rb +0 -11
- data/spec/code/object/boolean_spec.rb +0 -18
- data/spec/code/object/cryptography_spec.rb +0 -25
- data/spec/code/object/decimal_spec.rb +0 -50
- data/spec/code/object/dictionary_spec.rb +0 -98
- data/spec/code/object/function_spec.rb +0 -268
- data/spec/code/object/http_spec.rb +0 -33
- data/spec/code/object/ics_spec.rb +0 -50
- data/spec/code/object/integer_spec.rb +0 -42
- data/spec/code/object/list_spec.rb +0 -22
- data/spec/code/object/nothing_spec.rb +0 -14
- data/spec/code/object/range_spec.rb +0 -23
- data/spec/code/object/string_spec.rb +0 -26
- data/spec/code/parser/boolean_spec.rb +0 -11
- data/spec/code/parser/chained_call_spec.rb +0 -16
- data/spec/code/parser/dictionary_spec.rb +0 -18
- data/spec/code/parser/function_spec.rb +0 -16
- data/spec/code/parser/group_spec.rb +0 -11
- data/spec/code/parser/if_modifier_spec.rb +0 -18
- data/spec/code/parser/list_spec.rb +0 -17
- data/spec/code/parser/number_spec.rb +0 -11
- data/spec/code/parser/string_spec.rb +0 -20
- data/spec/code/parser_spec.rb +0 -52
- data/spec/code/type_spec.rb +0 -21
- data/spec/code_spec.rb +0 -717
- data/spec/spec_helper.rb +0 -21
- data/spec/zeitwerk/loader_spec.rb +0 -7
data/lib/code/object/integer.rb
CHANGED
|
@@ -3,6 +3,1020 @@
|
|
|
3
3
|
class Code
|
|
4
4
|
class Object
|
|
5
5
|
class Integer < Number
|
|
6
|
+
CLASS_DOCUMENTATION = {
|
|
7
|
+
name: "Integer",
|
|
8
|
+
description:
|
|
9
|
+
"represents whole numbers with arithmetic, bitwise operations, iteration, duration helpers, and numeric predicates.",
|
|
10
|
+
examples: ["Integer.new(1)", "12.digits", "3.times((i) => { i })"]
|
|
11
|
+
}.freeze
|
|
12
|
+
INSTANCE_FUNCTIONS = {
|
|
13
|
+
"%" => {
|
|
14
|
+
name: "%",
|
|
15
|
+
description: "returns the integer modulo another number.",
|
|
16
|
+
examples: ["5 % 2", "4 % 2", "7 % 3"]
|
|
17
|
+
},
|
|
18
|
+
"modulo" => {
|
|
19
|
+
name: "modulo",
|
|
20
|
+
description: "returns the integer modulo another number.",
|
|
21
|
+
examples: %w[5.modulo(2) 4.modulo(2) 7.modulo(3)]
|
|
22
|
+
},
|
|
23
|
+
"&" => {
|
|
24
|
+
name: "&",
|
|
25
|
+
description:
|
|
26
|
+
"returns the bitwise and of the integer and another number.",
|
|
27
|
+
examples: ["5 & 3", "4 & 1", "7 & 2"]
|
|
28
|
+
},
|
|
29
|
+
"bitwise_and" => {
|
|
30
|
+
name: "bitwise_and",
|
|
31
|
+
description:
|
|
32
|
+
"returns the bitwise and of the integer and another number.",
|
|
33
|
+
examples: %w[5.bitwise_and(3) 4.bitwise_and(1) 7.bitwise_and(2)]
|
|
34
|
+
},
|
|
35
|
+
"*" => {
|
|
36
|
+
name: "*",
|
|
37
|
+
description: "multiplies numbers or repeats text by the integer.",
|
|
38
|
+
examples: ["2 * 3", "2 * 3.5", "3 * :ha"]
|
|
39
|
+
},
|
|
40
|
+
"multiplication" => {
|
|
41
|
+
name: "multiplication",
|
|
42
|
+
description: "multiplies numbers or repeats text by the integer.",
|
|
43
|
+
examples: %w[
|
|
44
|
+
2.multiplication(3)
|
|
45
|
+
2.multiplication(3.5)
|
|
46
|
+
3.multiplication(:ha)
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"×" => {
|
|
50
|
+
name: "×",
|
|
51
|
+
description: "multiplies numbers or repeats text by the integer.",
|
|
52
|
+
examples: ["2 × 3", "2 × 3.5", "3 × :ha"]
|
|
53
|
+
},
|
|
54
|
+
"**" => {
|
|
55
|
+
name: "**",
|
|
56
|
+
description: "returns the integer raised to a power.",
|
|
57
|
+
examples: ["2 ** 3", "4 ** 2", "9 ** 0.5"]
|
|
58
|
+
},
|
|
59
|
+
"power" => {
|
|
60
|
+
name: "power",
|
|
61
|
+
description: "returns the integer raised to a power.",
|
|
62
|
+
examples: %w[2.power(3) 4.power(2) 9.power(0.5)]
|
|
63
|
+
},
|
|
64
|
+
"power_modulo" => {
|
|
65
|
+
name: "power_modulo",
|
|
66
|
+
description: "returns modular exponentiation.",
|
|
67
|
+
examples: [
|
|
68
|
+
"2.power_modulo(3, 5)",
|
|
69
|
+
"3.power_modulo(2, 7)",
|
|
70
|
+
"10.power_modulo(2, 6)"
|
|
71
|
+
]
|
|
72
|
+
},
|
|
73
|
+
"+" => {
|
|
74
|
+
name: "+",
|
|
75
|
+
description:
|
|
76
|
+
"returns the integer itself when unary, adds numbers, or joins other values as text.",
|
|
77
|
+
examples: ["1 + 2", "1 + 2.5", "+1"]
|
|
78
|
+
},
|
|
79
|
+
"plus" => {
|
|
80
|
+
name: "plus",
|
|
81
|
+
description: "adds numbers or joins non-numeric values as text.",
|
|
82
|
+
examples: %w[1.plus(2) 1.plus(2.5) 1.plus(:x)]
|
|
83
|
+
},
|
|
84
|
+
"-" => {
|
|
85
|
+
name: "-",
|
|
86
|
+
description:
|
|
87
|
+
"returns the integer negated when unary or minus another number.",
|
|
88
|
+
examples: ["5 - 1", "5 - 2.5", "-5"]
|
|
89
|
+
},
|
|
90
|
+
"minus" => {
|
|
91
|
+
name: "minus",
|
|
92
|
+
description: "returns the integer minus another number.",
|
|
93
|
+
examples: %w[5.minus(1) 5.minus(2.5) 1.minus(3)]
|
|
94
|
+
},
|
|
95
|
+
"unary_minus" => {
|
|
96
|
+
name: "unary_minus",
|
|
97
|
+
description: "returns the negated integer.",
|
|
98
|
+
examples: %w[5.unary_minus 0.unary_minus -5.unary_minus]
|
|
99
|
+
},
|
|
100
|
+
"/" => {
|
|
101
|
+
name: "/",
|
|
102
|
+
description:
|
|
103
|
+
"returns the integer divided by another number as a decimal.",
|
|
104
|
+
examples: ["5 / 2", "4 / 2", "7 / 3"]
|
|
105
|
+
},
|
|
106
|
+
"division" => {
|
|
107
|
+
name: "division",
|
|
108
|
+
description:
|
|
109
|
+
"returns the integer divided by another number as a decimal.",
|
|
110
|
+
examples: %w[5.division(2) 4.division(2) 7.division(3)]
|
|
111
|
+
},
|
|
112
|
+
"÷" => {
|
|
113
|
+
name: "÷",
|
|
114
|
+
description:
|
|
115
|
+
"returns the integer divided by another number as a decimal.",
|
|
116
|
+
examples: ["5 ÷ 2", "4 ÷ 2", "7 ÷ 3"]
|
|
117
|
+
},
|
|
118
|
+
"decimal_divide" => {
|
|
119
|
+
name: "decimal_divide",
|
|
120
|
+
description:
|
|
121
|
+
"returns the integer divided by another number as a decimal.",
|
|
122
|
+
examples: %w[
|
|
123
|
+
5.decimal_divide(2)
|
|
124
|
+
4.decimal_divide(2)
|
|
125
|
+
7.decimal_divide(3)
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
"digits" => {
|
|
129
|
+
name: "digits",
|
|
130
|
+
description:
|
|
131
|
+
"returns the integer digits in reverse order, optionally for a base.",
|
|
132
|
+
examples: %w[123.digits 123.digits(10) 10.digits(2)]
|
|
133
|
+
},
|
|
134
|
+
"bit_length" => {
|
|
135
|
+
name: "bit_length",
|
|
136
|
+
description:
|
|
137
|
+
"returns the number of bits needed to represent the integer.",
|
|
138
|
+
examples: %w[5.bit_length 0.bit_length 255.bit_length]
|
|
139
|
+
},
|
|
140
|
+
"all_bits?" => {
|
|
141
|
+
name: "all_bits?",
|
|
142
|
+
description: "returns whether every bit in a mask is set.",
|
|
143
|
+
examples: %w[7.all_bits?(3) 4.all_bits?(3) 0.all_bits?(1)]
|
|
144
|
+
},
|
|
145
|
+
"any_bits?" => {
|
|
146
|
+
name: "any_bits?",
|
|
147
|
+
description: "returns whether any bit in a mask is set.",
|
|
148
|
+
examples: %w[5.any_bits?(1) 4.any_bits?(1) 0.any_bits?(1)]
|
|
149
|
+
},
|
|
150
|
+
"no_bits?" => {
|
|
151
|
+
name: "no_bits?",
|
|
152
|
+
description: "returns whether no bits in a mask are set.",
|
|
153
|
+
examples: %w[4.no_bits?(1) 5.no_bits?(1) 0.no_bits?(1)]
|
|
154
|
+
},
|
|
155
|
+
"character" => {
|
|
156
|
+
name: "character",
|
|
157
|
+
description: "returns the character for the integer codepoint.",
|
|
158
|
+
examples: %w[65.character 97.character 48.character]
|
|
159
|
+
},
|
|
160
|
+
"greatest_common_denominator" => {
|
|
161
|
+
name: "greatest_common_denominator",
|
|
162
|
+
description:
|
|
163
|
+
"returns the greatest common divisor with another integer.",
|
|
164
|
+
examples: %w[
|
|
165
|
+
12.greatest_common_denominator(8)
|
|
166
|
+
21.greatest_common_denominator(14)
|
|
167
|
+
5.greatest_common_denominator(2)
|
|
168
|
+
]
|
|
169
|
+
},
|
|
170
|
+
"lowest_common_multiple" => {
|
|
171
|
+
name: "lowest_common_multiple",
|
|
172
|
+
description:
|
|
173
|
+
"returns the least common multiple with another integer.",
|
|
174
|
+
examples: %w[
|
|
175
|
+
4.lowest_common_multiple(6)
|
|
176
|
+
3.lowest_common_multiple(7)
|
|
177
|
+
5.lowest_common_multiple(10)
|
|
178
|
+
]
|
|
179
|
+
},
|
|
180
|
+
"<<" => {
|
|
181
|
+
name: "<<",
|
|
182
|
+
description: "returns the integer shifted left by a bit count.",
|
|
183
|
+
examples: ["5 << 1", "4 << 2", "1 << 3"]
|
|
184
|
+
},
|
|
185
|
+
"left_shift" => {
|
|
186
|
+
name: "left_shift",
|
|
187
|
+
description: "returns the integer shifted left by a bit count.",
|
|
188
|
+
examples: %w[5.left_shift(1) 4.left_shift(2) 1.left_shift(3)]
|
|
189
|
+
},
|
|
190
|
+
">>" => {
|
|
191
|
+
name: ">>",
|
|
192
|
+
description: "returns the integer shifted right by a bit count.",
|
|
193
|
+
examples: ["5 >> 1", "4 >> 1", "8 >> 2"]
|
|
194
|
+
},
|
|
195
|
+
"right_shift" => {
|
|
196
|
+
name: "right_shift",
|
|
197
|
+
description: "returns the integer shifted right by a bit count.",
|
|
198
|
+
examples: %w[5.right_shift(1) 4.right_shift(1) 8.right_shift(2)]
|
|
199
|
+
},
|
|
200
|
+
"^" => {
|
|
201
|
+
name: "^",
|
|
202
|
+
description:
|
|
203
|
+
"returns the bitwise xor of the integer and another number.",
|
|
204
|
+
examples: ["5 ^ 3", "4 ^ 1", "7 ^ 2"]
|
|
205
|
+
},
|
|
206
|
+
"bitwise_xor" => {
|
|
207
|
+
name: "bitwise_xor",
|
|
208
|
+
description:
|
|
209
|
+
"returns the bitwise xor of the integer and another number.",
|
|
210
|
+
examples: %w[5.bitwise_xor(3) 4.bitwise_xor(1) 7.bitwise_xor(2)]
|
|
211
|
+
},
|
|
212
|
+
"abs" => {
|
|
213
|
+
name: "abs",
|
|
214
|
+
description: "returns the absolute value of the integer.",
|
|
215
|
+
examples: %w[-1.abs 1.abs 0.abs]
|
|
216
|
+
},
|
|
217
|
+
"between?" => {
|
|
218
|
+
name: "between?",
|
|
219
|
+
description: "returns whether the integer is between two bounds.",
|
|
220
|
+
examples: ["2.between?(1, 3)", "4.between?(1, 3)", "1.between?(1, 3)"]
|
|
221
|
+
},
|
|
222
|
+
"clamp" => {
|
|
223
|
+
name: "clamp",
|
|
224
|
+
description: "returns the integer constrained between two bounds.",
|
|
225
|
+
examples: ["5.clamp(1, 3)", "0.clamp(1, 3)", "2.clamp(1, 3)"]
|
|
226
|
+
},
|
|
227
|
+
"divide" => {
|
|
228
|
+
name: "divide",
|
|
229
|
+
description:
|
|
230
|
+
"returns integer division of the integer by another number.",
|
|
231
|
+
examples: %w[5.divide(2) 10.divide(3) 9.divide(2)]
|
|
232
|
+
},
|
|
233
|
+
"divide_modulo" => {
|
|
234
|
+
name: "divide_modulo",
|
|
235
|
+
description: "returns integer division and modulo results as a list.",
|
|
236
|
+
examples: %w[
|
|
237
|
+
5.divide_modulo(2)
|
|
238
|
+
10.divide_modulo(3)
|
|
239
|
+
9.divide_modulo(2)
|
|
240
|
+
]
|
|
241
|
+
},
|
|
242
|
+
"ceil" => {
|
|
243
|
+
name: "ceil",
|
|
244
|
+
description:
|
|
245
|
+
"returns the integer rounded toward positive infinity at an optional precision.",
|
|
246
|
+
examples: %w[12.ceil 123.ceil(-1) -123.ceil(-1)]
|
|
247
|
+
},
|
|
248
|
+
"ceil_divide" => {
|
|
249
|
+
name: "ceil_divide",
|
|
250
|
+
description:
|
|
251
|
+
"returns division by another number rounded up to an integer.",
|
|
252
|
+
examples: %w[5.ceil_divide(2) 4.ceil_divide(2) 7.ceil_divide(3)]
|
|
253
|
+
},
|
|
254
|
+
"day" => {
|
|
255
|
+
name: "day",
|
|
256
|
+
description: "returns a duration of this many days.",
|
|
257
|
+
examples: %w[1.day 2.day 0.day]
|
|
258
|
+
},
|
|
259
|
+
"days" => {
|
|
260
|
+
name: "days",
|
|
261
|
+
description: "returns a duration of this many days.",
|
|
262
|
+
examples: %w[1.days 2.days 0.days]
|
|
263
|
+
},
|
|
264
|
+
"decrement!" => {
|
|
265
|
+
name: "decrement!",
|
|
266
|
+
description:
|
|
267
|
+
"subtracts a value from the integer in place and returns it.",
|
|
268
|
+
examples: [
|
|
269
|
+
"i = 2 i.decrement!",
|
|
270
|
+
"i = 2 i.decrement!(2)",
|
|
271
|
+
"i = 0 i.decrement!"
|
|
272
|
+
]
|
|
273
|
+
},
|
|
274
|
+
"decrement" => {
|
|
275
|
+
name: "decrement",
|
|
276
|
+
description: "returns the integer minus a value, defaulting to one.",
|
|
277
|
+
examples: %w[2.decrement 2.decrement(2) 0.decrement]
|
|
278
|
+
},
|
|
279
|
+
"even?" => {
|
|
280
|
+
name: "even?",
|
|
281
|
+
description: "returns whether the integer is even.",
|
|
282
|
+
examples: %w[2.even? 1.even? 0.even?]
|
|
283
|
+
},
|
|
284
|
+
"floor" => {
|
|
285
|
+
name: "floor",
|
|
286
|
+
description:
|
|
287
|
+
"returns the integer rounded toward negative infinity at an optional precision.",
|
|
288
|
+
examples: %w[12.floor 123.floor(-1) -123.floor(-1)]
|
|
289
|
+
},
|
|
290
|
+
"hour" => {
|
|
291
|
+
name: "hour",
|
|
292
|
+
description: "returns a duration of this many hours.",
|
|
293
|
+
examples: %w[1.hour 2.hour 0.hour]
|
|
294
|
+
},
|
|
295
|
+
"hours" => {
|
|
296
|
+
name: "hours",
|
|
297
|
+
description: "returns a duration of this many hours.",
|
|
298
|
+
examples: %w[1.hours 2.hours 0.hours]
|
|
299
|
+
},
|
|
300
|
+
"increment!" => {
|
|
301
|
+
name: "increment!",
|
|
302
|
+
description: "adds a value to the integer in place and returns it.",
|
|
303
|
+
examples: [
|
|
304
|
+
"i = 1 i.increment!",
|
|
305
|
+
"i = 1 i.increment!(2)",
|
|
306
|
+
"i = 0 i.increment!"
|
|
307
|
+
]
|
|
308
|
+
},
|
|
309
|
+
"increment" => {
|
|
310
|
+
name: "increment",
|
|
311
|
+
description: "returns the integer plus a value, defaulting to one.",
|
|
312
|
+
examples: %w[1.increment 1.increment(2) 0.increment]
|
|
313
|
+
},
|
|
314
|
+
"odd?" => {
|
|
315
|
+
name: "odd?",
|
|
316
|
+
description: "returns whether the integer is odd.",
|
|
317
|
+
examples: %w[1.odd? 2.odd? 0.odd?]
|
|
318
|
+
},
|
|
319
|
+
"minute" => {
|
|
320
|
+
name: "minute",
|
|
321
|
+
description: "returns a duration of this many minutes.",
|
|
322
|
+
examples: %w[1.minute 2.minute 0.minute]
|
|
323
|
+
},
|
|
324
|
+
"minutes" => {
|
|
325
|
+
name: "minutes",
|
|
326
|
+
description: "returns a duration of this many minutes.",
|
|
327
|
+
examples: %w[1.minutes 2.minutes 0.minutes]
|
|
328
|
+
},
|
|
329
|
+
"month" => {
|
|
330
|
+
name: "month",
|
|
331
|
+
description: "returns a duration of this many months.",
|
|
332
|
+
examples: %w[1.month 2.month 0.month]
|
|
333
|
+
},
|
|
334
|
+
"months" => {
|
|
335
|
+
name: "months",
|
|
336
|
+
description: "returns a duration of this many months.",
|
|
337
|
+
examples: %w[1.months 2.months 0.months]
|
|
338
|
+
},
|
|
339
|
+
"round" => {
|
|
340
|
+
name: "round",
|
|
341
|
+
description: "returns the integer rounded to a precision.",
|
|
342
|
+
examples: %w[12.round 123.round(-1) -123.round(-1)]
|
|
343
|
+
},
|
|
344
|
+
"second" => {
|
|
345
|
+
name: "second",
|
|
346
|
+
description: "returns a duration of this many seconds.",
|
|
347
|
+
examples: %w[1.second 2.second 0.second]
|
|
348
|
+
},
|
|
349
|
+
"seconds" => {
|
|
350
|
+
name: "seconds",
|
|
351
|
+
description: "returns a duration of this many seconds.",
|
|
352
|
+
examples: %w[1.seconds 2.seconds 0.seconds]
|
|
353
|
+
},
|
|
354
|
+
"sqrt" => {
|
|
355
|
+
name: "sqrt",
|
|
356
|
+
description: "returns the square root of the integer.",
|
|
357
|
+
examples: %w[4.sqrt 9.sqrt 2.sqrt]
|
|
358
|
+
},
|
|
359
|
+
"times" => {
|
|
360
|
+
name: "times",
|
|
361
|
+
description:
|
|
362
|
+
"calls a function once for each number from zero up to the integer and returns the integer.",
|
|
363
|
+
examples: [
|
|
364
|
+
"3.times((i) => { i })",
|
|
365
|
+
"0.times((i) => { i })",
|
|
366
|
+
"2.times((i, count) => { count })"
|
|
367
|
+
]
|
|
368
|
+
},
|
|
369
|
+
"down_to" => {
|
|
370
|
+
name: "down_to",
|
|
371
|
+
description:
|
|
372
|
+
"calls a function for each integer from this value down to a target and returns the integer.",
|
|
373
|
+
examples: [
|
|
374
|
+
"3.down_to(1, (i) => { i })",
|
|
375
|
+
"3.down_to(1, (i, index) => { index })",
|
|
376
|
+
"1.down_to(1, (i) => { i })"
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
"up_to" => {
|
|
380
|
+
name: "up_to",
|
|
381
|
+
description:
|
|
382
|
+
"calls a function for each integer from this value up to a target and returns the integer.",
|
|
383
|
+
examples: [
|
|
384
|
+
"1.up_to(3, (i) => { i })",
|
|
385
|
+
"1.up_to(3, (i, index) => { index })",
|
|
386
|
+
"1.up_to(1, (i) => { i })"
|
|
387
|
+
]
|
|
388
|
+
},
|
|
389
|
+
"truncate" => {
|
|
390
|
+
name: "truncate",
|
|
391
|
+
description: "returns the integer truncated to a precision.",
|
|
392
|
+
examples: %w[12.truncate 123.truncate(-1) -123.truncate(-1)]
|
|
393
|
+
},
|
|
394
|
+
"week" => {
|
|
395
|
+
name: "week",
|
|
396
|
+
description: "returns a duration of this many weeks.",
|
|
397
|
+
examples: %w[1.week 2.week 0.week]
|
|
398
|
+
},
|
|
399
|
+
"weeks" => {
|
|
400
|
+
name: "weeks",
|
|
401
|
+
description: "returns a duration of this many weeks.",
|
|
402
|
+
examples: %w[1.weeks 2.weeks 0.weeks]
|
|
403
|
+
},
|
|
404
|
+
"year" => {
|
|
405
|
+
name: "year",
|
|
406
|
+
description: "returns a duration of this many years.",
|
|
407
|
+
examples: %w[1.year 2.year 0.year]
|
|
408
|
+
},
|
|
409
|
+
"years" => {
|
|
410
|
+
name: "years",
|
|
411
|
+
description: "returns a duration of this many years.",
|
|
412
|
+
examples: %w[1.years 2.years 0.years]
|
|
413
|
+
},
|
|
414
|
+
"|" => {
|
|
415
|
+
name: "|",
|
|
416
|
+
description:
|
|
417
|
+
"returns the bitwise or of the integer and another number.",
|
|
418
|
+
examples: ["5 | 2", "4 | 1", "7 | 2"]
|
|
419
|
+
},
|
|
420
|
+
"bitwise_or" => {
|
|
421
|
+
name: "bitwise_or",
|
|
422
|
+
description:
|
|
423
|
+
"returns the bitwise or of the integer and another number.",
|
|
424
|
+
examples: %w[5.bitwise_or(2) 4.bitwise_or(1) 7.bitwise_or(2)]
|
|
425
|
+
},
|
|
426
|
+
"many?" => {
|
|
427
|
+
name: "many?",
|
|
428
|
+
description: "returns whether the integer is greater than one.",
|
|
429
|
+
examples: %w[2.many? 1.many? 0.many?]
|
|
430
|
+
},
|
|
431
|
+
"any?" => {
|
|
432
|
+
name: "any?",
|
|
433
|
+
description: "returns whether the integer is greater than zero.",
|
|
434
|
+
examples: %w[1.any? 0.any? -1.any?]
|
|
435
|
+
},
|
|
436
|
+
"positive?" => {
|
|
437
|
+
name: "positive?",
|
|
438
|
+
description: "returns whether the integer is positive.",
|
|
439
|
+
examples: %w[1.positive? 0.positive? -1.positive?]
|
|
440
|
+
},
|
|
441
|
+
"negative?" => {
|
|
442
|
+
name: "negative?",
|
|
443
|
+
description: "returns whether the integer is negative.",
|
|
444
|
+
examples: %w[-1.negative? 0.negative? 1.negative?]
|
|
445
|
+
},
|
|
446
|
+
"next" => {
|
|
447
|
+
name: "next",
|
|
448
|
+
description: "returns the integer plus one.",
|
|
449
|
+
examples: %w[1.next 0.next -1.next]
|
|
450
|
+
},
|
|
451
|
+
"successor" => {
|
|
452
|
+
name: "successor",
|
|
453
|
+
description: "returns the integer plus one.",
|
|
454
|
+
examples: %w[1.successor 0.successor -1.successor]
|
|
455
|
+
},
|
|
456
|
+
"previous" => {
|
|
457
|
+
name: "previous",
|
|
458
|
+
description: "returns the integer minus one.",
|
|
459
|
+
examples: %w[1.previous 0.previous -1.previous]
|
|
460
|
+
},
|
|
461
|
+
"predecessor" => {
|
|
462
|
+
name: "predecessor",
|
|
463
|
+
description: "returns the integer minus one.",
|
|
464
|
+
examples: %w[1.predecessor 0.predecessor -1.predecessor]
|
|
465
|
+
},
|
|
466
|
+
"remainder" => {
|
|
467
|
+
name: "remainder",
|
|
468
|
+
description:
|
|
469
|
+
"returns the remainder after division by another number.",
|
|
470
|
+
examples: %w[5.remainder(2) 10.remainder(3) 9.remainder(2)]
|
|
471
|
+
},
|
|
472
|
+
"non_zero?" => {
|
|
473
|
+
name: "non_zero?",
|
|
474
|
+
description: "returns whether the integer is not zero.",
|
|
475
|
+
examples: %w[1.non_zero? 0.non_zero? -1.non_zero?]
|
|
476
|
+
},
|
|
477
|
+
"integer?" => {
|
|
478
|
+
name: "integer?",
|
|
479
|
+
description: "returns whether the value is an integer.",
|
|
480
|
+
examples: %w[1.integer? 0.integer? -1.integer?]
|
|
481
|
+
},
|
|
482
|
+
"finite?" => {
|
|
483
|
+
name: "finite?",
|
|
484
|
+
description: "returns whether the integer is finite.",
|
|
485
|
+
examples: %w[1.finite? 0.finite? -1.finite?]
|
|
486
|
+
},
|
|
487
|
+
"infinite?" => {
|
|
488
|
+
name: "infinite?",
|
|
489
|
+
description: "returns whether the integer is infinite.",
|
|
490
|
+
examples: %w[1.infinite? 0.infinite? -1.infinite?]
|
|
491
|
+
},
|
|
492
|
+
"numerator" => {
|
|
493
|
+
name: "numerator",
|
|
494
|
+
description: "returns the integer numerator.",
|
|
495
|
+
examples: %w[1.numerator 0.numerator -1.numerator]
|
|
496
|
+
},
|
|
497
|
+
"denominator" => {
|
|
498
|
+
name: "denominator",
|
|
499
|
+
description: "returns one as the integer denominator.",
|
|
500
|
+
examples: %w[1.denominator 0.denominator -1.denominator]
|
|
501
|
+
},
|
|
502
|
+
"magnitude" => {
|
|
503
|
+
name: "magnitude",
|
|
504
|
+
description: "returns the absolute value of the integer.",
|
|
505
|
+
examples: %w[-1.magnitude 1.magnitude 0.magnitude]
|
|
506
|
+
},
|
|
507
|
+
"zero?" => {
|
|
508
|
+
name: "zero?",
|
|
509
|
+
description: "returns whether the integer is zero.",
|
|
510
|
+
examples: %w[0.zero? 1.zero? -1.zero?]
|
|
511
|
+
},
|
|
512
|
+
"one?" => {
|
|
513
|
+
name: "one?",
|
|
514
|
+
description: "returns whether the integer is one.",
|
|
515
|
+
examples: %w[1.one? 2.one? 0.one?]
|
|
516
|
+
},
|
|
517
|
+
"two?" => {
|
|
518
|
+
name: "two?",
|
|
519
|
+
description: "returns whether the integer is two.",
|
|
520
|
+
examples: %w[2.two? 3.two? 0.two?]
|
|
521
|
+
},
|
|
522
|
+
"three?" => {
|
|
523
|
+
name: "three?",
|
|
524
|
+
description: "returns whether the integer is three.",
|
|
525
|
+
examples: %w[3.three? 4.three? 0.three?]
|
|
526
|
+
},
|
|
527
|
+
"four?" => {
|
|
528
|
+
name: "four?",
|
|
529
|
+
description: "returns whether the integer is four.",
|
|
530
|
+
examples: %w[4.four? 5.four? 0.four?]
|
|
531
|
+
},
|
|
532
|
+
"five?" => {
|
|
533
|
+
name: "five?",
|
|
534
|
+
description: "returns whether the integer is five.",
|
|
535
|
+
examples: %w[5.five? 6.five? 0.five?]
|
|
536
|
+
},
|
|
537
|
+
"six?" => {
|
|
538
|
+
name: "six?",
|
|
539
|
+
description: "returns whether the integer is six.",
|
|
540
|
+
examples: %w[6.six? 7.six? 0.six?]
|
|
541
|
+
},
|
|
542
|
+
"seven?" => {
|
|
543
|
+
name: "seven?",
|
|
544
|
+
description: "returns whether the integer is seven.",
|
|
545
|
+
examples: %w[7.seven? 8.seven? 0.seven?]
|
|
546
|
+
},
|
|
547
|
+
"eight?" => {
|
|
548
|
+
name: "eight?",
|
|
549
|
+
description: "returns whether the integer is eight.",
|
|
550
|
+
examples: %w[8.eight? 9.eight? 0.eight?]
|
|
551
|
+
},
|
|
552
|
+
"nine?" => {
|
|
553
|
+
name: "nine?",
|
|
554
|
+
description: "returns whether the integer is nine.",
|
|
555
|
+
examples: %w[9.nine? 10.nine? 0.nine?]
|
|
556
|
+
},
|
|
557
|
+
"ten?" => {
|
|
558
|
+
name: "ten?",
|
|
559
|
+
description: "returns whether the integer is ten.",
|
|
560
|
+
examples: %w[10.ten? 11.ten? 0.ten?]
|
|
561
|
+
},
|
|
562
|
+
"eleven?" => {
|
|
563
|
+
name: "eleven?",
|
|
564
|
+
description: "returns whether the integer is eleven.",
|
|
565
|
+
examples: %w[11.eleven? 12.eleven? 0.eleven?]
|
|
566
|
+
},
|
|
567
|
+
"twelve?" => {
|
|
568
|
+
name: "twelve?",
|
|
569
|
+
description: "returns whether the integer is twelve.",
|
|
570
|
+
examples: %w[12.twelve? 13.twelve? 0.twelve?]
|
|
571
|
+
},
|
|
572
|
+
"thirteen?" => {
|
|
573
|
+
name: "thirteen?",
|
|
574
|
+
description: "returns whether the integer is thirteen.",
|
|
575
|
+
examples: %w[13.thirteen? 14.thirteen? 0.thirteen?]
|
|
576
|
+
},
|
|
577
|
+
"fourteen?" => {
|
|
578
|
+
name: "fourteen?",
|
|
579
|
+
description: "returns whether the integer is fourteen.",
|
|
580
|
+
examples: %w[14.fourteen? 15.fourteen? 0.fourteen?]
|
|
581
|
+
},
|
|
582
|
+
"fifteen?" => {
|
|
583
|
+
name: "fifteen?",
|
|
584
|
+
description: "returns whether the integer is fifteen.",
|
|
585
|
+
examples: %w[15.fifteen? 16.fifteen? 0.fifteen?]
|
|
586
|
+
},
|
|
587
|
+
"sixteen?" => {
|
|
588
|
+
name: "sixteen?",
|
|
589
|
+
description: "returns whether the integer is sixteen.",
|
|
590
|
+
examples: %w[16.sixteen? 17.sixteen? 0.sixteen?]
|
|
591
|
+
},
|
|
592
|
+
"seventeen?" => {
|
|
593
|
+
name: "seventeen?",
|
|
594
|
+
description: "returns whether the integer is seventeen.",
|
|
595
|
+
examples: %w[17.seventeen? 18.seventeen? 0.seventeen?]
|
|
596
|
+
},
|
|
597
|
+
"eighteen?" => {
|
|
598
|
+
name: "eighteen?",
|
|
599
|
+
description: "returns whether the integer is eighteen.",
|
|
600
|
+
examples: %w[18.eighteen? 19.eighteen? 0.eighteen?]
|
|
601
|
+
},
|
|
602
|
+
"nineteen?" => {
|
|
603
|
+
name: "nineteen?",
|
|
604
|
+
description: "returns whether the integer is nineteen.",
|
|
605
|
+
examples: %w[19.nineteen? 20.nineteen? 0.nineteen?]
|
|
606
|
+
},
|
|
607
|
+
"twenty?" => {
|
|
608
|
+
name: "twenty?",
|
|
609
|
+
description: "returns whether the integer is twenty.",
|
|
610
|
+
examples: %w[20.twenty? 21.twenty? 0.twenty?]
|
|
611
|
+
},
|
|
612
|
+
"twenty_one?" => {
|
|
613
|
+
name: "twenty_one?",
|
|
614
|
+
description: "returns whether the integer is twenty one.",
|
|
615
|
+
examples: %w[21.twenty_one? 22.twenty_one? 0.twenty_one?]
|
|
616
|
+
},
|
|
617
|
+
"twenty_two?" => {
|
|
618
|
+
name: "twenty_two?",
|
|
619
|
+
description: "returns whether the integer is twenty two.",
|
|
620
|
+
examples: %w[22.twenty_two? 23.twenty_two? 0.twenty_two?]
|
|
621
|
+
},
|
|
622
|
+
"twenty_three?" => {
|
|
623
|
+
name: "twenty_three?",
|
|
624
|
+
description: "returns whether the integer is twenty three.",
|
|
625
|
+
examples: %w[23.twenty_three? 24.twenty_three? 0.twenty_three?]
|
|
626
|
+
},
|
|
627
|
+
"twenty_four?" => {
|
|
628
|
+
name: "twenty_four?",
|
|
629
|
+
description: "returns whether the integer is twenty four.",
|
|
630
|
+
examples: %w[24.twenty_four? 25.twenty_four? 0.twenty_four?]
|
|
631
|
+
},
|
|
632
|
+
"twenty_five?" => {
|
|
633
|
+
name: "twenty_five?",
|
|
634
|
+
description: "returns whether the integer is twenty five.",
|
|
635
|
+
examples: %w[25.twenty_five? 26.twenty_five? 0.twenty_five?]
|
|
636
|
+
},
|
|
637
|
+
"twenty_six?" => {
|
|
638
|
+
name: "twenty_six?",
|
|
639
|
+
description: "returns whether the integer is twenty six.",
|
|
640
|
+
examples: %w[26.twenty_six? 27.twenty_six? 0.twenty_six?]
|
|
641
|
+
},
|
|
642
|
+
"twenty_seven?" => {
|
|
643
|
+
name: "twenty_seven?",
|
|
644
|
+
description: "returns whether the integer is twenty seven.",
|
|
645
|
+
examples: %w[27.twenty_seven? 28.twenty_seven? 0.twenty_seven?]
|
|
646
|
+
},
|
|
647
|
+
"twenty_eight?" => {
|
|
648
|
+
name: "twenty_eight?",
|
|
649
|
+
description: "returns whether the integer is twenty eight.",
|
|
650
|
+
examples: %w[28.twenty_eight? 29.twenty_eight? 0.twenty_eight?]
|
|
651
|
+
},
|
|
652
|
+
"twenty_nine?" => {
|
|
653
|
+
name: "twenty_nine?",
|
|
654
|
+
description: "returns whether the integer is twenty nine.",
|
|
655
|
+
examples: %w[29.twenty_nine? 30.twenty_nine? 0.twenty_nine?]
|
|
656
|
+
},
|
|
657
|
+
"thirty?" => {
|
|
658
|
+
name: "thirty?",
|
|
659
|
+
description: "returns whether the integer is thirty.",
|
|
660
|
+
examples: %w[30.thirty? 31.thirty? 0.thirty?]
|
|
661
|
+
},
|
|
662
|
+
"thirty_one?" => {
|
|
663
|
+
name: "thirty_one?",
|
|
664
|
+
description: "returns whether the integer is thirty one.",
|
|
665
|
+
examples: %w[31.thirty_one? 32.thirty_one? 0.thirty_one?]
|
|
666
|
+
},
|
|
667
|
+
"thirty_two?" => {
|
|
668
|
+
name: "thirty_two?",
|
|
669
|
+
description: "returns whether the integer is thirty two.",
|
|
670
|
+
examples: %w[32.thirty_two? 33.thirty_two? 0.thirty_two?]
|
|
671
|
+
},
|
|
672
|
+
"thirty_three?" => {
|
|
673
|
+
name: "thirty_three?",
|
|
674
|
+
description: "returns whether the integer is thirty three.",
|
|
675
|
+
examples: %w[33.thirty_three? 34.thirty_three? 0.thirty_three?]
|
|
676
|
+
},
|
|
677
|
+
"thirty_four?" => {
|
|
678
|
+
name: "thirty_four?",
|
|
679
|
+
description: "returns whether the integer is thirty four.",
|
|
680
|
+
examples: %w[34.thirty_four? 35.thirty_four? 0.thirty_four?]
|
|
681
|
+
},
|
|
682
|
+
"thirty_five?" => {
|
|
683
|
+
name: "thirty_five?",
|
|
684
|
+
description: "returns whether the integer is thirty five.",
|
|
685
|
+
examples: %w[35.thirty_five? 36.thirty_five? 0.thirty_five?]
|
|
686
|
+
},
|
|
687
|
+
"thirty_six?" => {
|
|
688
|
+
name: "thirty_six?",
|
|
689
|
+
description: "returns whether the integer is thirty six.",
|
|
690
|
+
examples: %w[36.thirty_six? 37.thirty_six? 0.thirty_six?]
|
|
691
|
+
},
|
|
692
|
+
"thirty_seven?" => {
|
|
693
|
+
name: "thirty_seven?",
|
|
694
|
+
description: "returns whether the integer is thirty seven.",
|
|
695
|
+
examples: %w[37.thirty_seven? 38.thirty_seven? 0.thirty_seven?]
|
|
696
|
+
},
|
|
697
|
+
"thirty_eight?" => {
|
|
698
|
+
name: "thirty_eight?",
|
|
699
|
+
description: "returns whether the integer is thirty eight.",
|
|
700
|
+
examples: %w[38.thirty_eight? 39.thirty_eight? 0.thirty_eight?]
|
|
701
|
+
},
|
|
702
|
+
"thirty_nine?" => {
|
|
703
|
+
name: "thirty_nine?",
|
|
704
|
+
description: "returns whether the integer is thirty nine.",
|
|
705
|
+
examples: %w[39.thirty_nine? 40.thirty_nine? 0.thirty_nine?]
|
|
706
|
+
},
|
|
707
|
+
"forty?" => {
|
|
708
|
+
name: "forty?",
|
|
709
|
+
description: "returns whether the integer is forty.",
|
|
710
|
+
examples: %w[40.forty? 41.forty? 0.forty?]
|
|
711
|
+
},
|
|
712
|
+
"forty_one?" => {
|
|
713
|
+
name: "forty_one?",
|
|
714
|
+
description: "returns whether the integer is forty one.",
|
|
715
|
+
examples: %w[41.forty_one? 42.forty_one? 0.forty_one?]
|
|
716
|
+
},
|
|
717
|
+
"forty_two?" => {
|
|
718
|
+
name: "forty_two?",
|
|
719
|
+
description: "returns whether the integer is forty two.",
|
|
720
|
+
examples: %w[42.forty_two? 43.forty_two? 0.forty_two?]
|
|
721
|
+
},
|
|
722
|
+
"forty_three?" => {
|
|
723
|
+
name: "forty_three?",
|
|
724
|
+
description: "returns whether the integer is forty three.",
|
|
725
|
+
examples: %w[43.forty_three? 44.forty_three? 0.forty_three?]
|
|
726
|
+
},
|
|
727
|
+
"forty_four?" => {
|
|
728
|
+
name: "forty_four?",
|
|
729
|
+
description: "returns whether the integer is forty four.",
|
|
730
|
+
examples: %w[44.forty_four? 45.forty_four? 0.forty_four?]
|
|
731
|
+
},
|
|
732
|
+
"forty_five?" => {
|
|
733
|
+
name: "forty_five?",
|
|
734
|
+
description: "returns whether the integer is forty five.",
|
|
735
|
+
examples: %w[45.forty_five? 46.forty_five? 0.forty_five?]
|
|
736
|
+
},
|
|
737
|
+
"forty_six?" => {
|
|
738
|
+
name: "forty_six?",
|
|
739
|
+
description: "returns whether the integer is forty six.",
|
|
740
|
+
examples: %w[46.forty_six? 47.forty_six? 0.forty_six?]
|
|
741
|
+
},
|
|
742
|
+
"forty_seven?" => {
|
|
743
|
+
name: "forty_seven?",
|
|
744
|
+
description: "returns whether the integer is forty seven.",
|
|
745
|
+
examples: %w[47.forty_seven? 48.forty_seven? 0.forty_seven?]
|
|
746
|
+
},
|
|
747
|
+
"forty_eight?" => {
|
|
748
|
+
name: "forty_eight?",
|
|
749
|
+
description: "returns whether the integer is forty eight.",
|
|
750
|
+
examples: %w[48.forty_eight? 49.forty_eight? 0.forty_eight?]
|
|
751
|
+
},
|
|
752
|
+
"forty_nine?" => {
|
|
753
|
+
name: "forty_nine?",
|
|
754
|
+
description: "returns whether the integer is forty nine.",
|
|
755
|
+
examples: %w[49.forty_nine? 50.forty_nine? 0.forty_nine?]
|
|
756
|
+
},
|
|
757
|
+
"fifty?" => {
|
|
758
|
+
name: "fifty?",
|
|
759
|
+
description: "returns whether the integer is fifty.",
|
|
760
|
+
examples: %w[50.fifty? 51.fifty? 0.fifty?]
|
|
761
|
+
},
|
|
762
|
+
"fifty_one?" => {
|
|
763
|
+
name: "fifty_one?",
|
|
764
|
+
description: "returns whether the integer is fifty one.",
|
|
765
|
+
examples: %w[51.fifty_one? 52.fifty_one? 0.fifty_one?]
|
|
766
|
+
},
|
|
767
|
+
"fifty_two?" => {
|
|
768
|
+
name: "fifty_two?",
|
|
769
|
+
description: "returns whether the integer is fifty two.",
|
|
770
|
+
examples: %w[52.fifty_two? 53.fifty_two? 0.fifty_two?]
|
|
771
|
+
},
|
|
772
|
+
"fifty_three?" => {
|
|
773
|
+
name: "fifty_three?",
|
|
774
|
+
description: "returns whether the integer is fifty three.",
|
|
775
|
+
examples: %w[53.fifty_three? 54.fifty_three? 0.fifty_three?]
|
|
776
|
+
},
|
|
777
|
+
"fifty_four?" => {
|
|
778
|
+
name: "fifty_four?",
|
|
779
|
+
description: "returns whether the integer is fifty four.",
|
|
780
|
+
examples: %w[54.fifty_four? 55.fifty_four? 0.fifty_four?]
|
|
781
|
+
},
|
|
782
|
+
"fifty_five?" => {
|
|
783
|
+
name: "fifty_five?",
|
|
784
|
+
description: "returns whether the integer is fifty five.",
|
|
785
|
+
examples: %w[55.fifty_five? 56.fifty_five? 0.fifty_five?]
|
|
786
|
+
},
|
|
787
|
+
"fifty_six?" => {
|
|
788
|
+
name: "fifty_six?",
|
|
789
|
+
description: "returns whether the integer is fifty six.",
|
|
790
|
+
examples: %w[56.fifty_six? 57.fifty_six? 0.fifty_six?]
|
|
791
|
+
},
|
|
792
|
+
"fifty_seven?" => {
|
|
793
|
+
name: "fifty_seven?",
|
|
794
|
+
description: "returns whether the integer is fifty seven.",
|
|
795
|
+
examples: %w[57.fifty_seven? 58.fifty_seven? 0.fifty_seven?]
|
|
796
|
+
},
|
|
797
|
+
"fifty_eight?" => {
|
|
798
|
+
name: "fifty_eight?",
|
|
799
|
+
description: "returns whether the integer is fifty eight.",
|
|
800
|
+
examples: %w[58.fifty_eight? 59.fifty_eight? 0.fifty_eight?]
|
|
801
|
+
},
|
|
802
|
+
"fifty_nine?" => {
|
|
803
|
+
name: "fifty_nine?",
|
|
804
|
+
description: "returns whether the integer is fifty nine.",
|
|
805
|
+
examples: %w[59.fifty_nine? 60.fifty_nine? 0.fifty_nine?]
|
|
806
|
+
},
|
|
807
|
+
"sixty?" => {
|
|
808
|
+
name: "sixty?",
|
|
809
|
+
description: "returns whether the integer is sixty.",
|
|
810
|
+
examples: %w[60.sixty? 61.sixty? 0.sixty?]
|
|
811
|
+
},
|
|
812
|
+
"sixty_one?" => {
|
|
813
|
+
name: "sixty_one?",
|
|
814
|
+
description: "returns whether the integer is sixty one.",
|
|
815
|
+
examples: %w[61.sixty_one? 62.sixty_one? 0.sixty_one?]
|
|
816
|
+
},
|
|
817
|
+
"sixty_two?" => {
|
|
818
|
+
name: "sixty_two?",
|
|
819
|
+
description: "returns whether the integer is sixty two.",
|
|
820
|
+
examples: %w[62.sixty_two? 63.sixty_two? 0.sixty_two?]
|
|
821
|
+
},
|
|
822
|
+
"sixty_three?" => {
|
|
823
|
+
name: "sixty_three?",
|
|
824
|
+
description: "returns whether the integer is sixty three.",
|
|
825
|
+
examples: %w[63.sixty_three? 64.sixty_three? 0.sixty_three?]
|
|
826
|
+
},
|
|
827
|
+
"sixty_four?" => {
|
|
828
|
+
name: "sixty_four?",
|
|
829
|
+
description: "returns whether the integer is sixty four.",
|
|
830
|
+
examples: %w[64.sixty_four? 65.sixty_four? 0.sixty_four?]
|
|
831
|
+
},
|
|
832
|
+
"sixty_five?" => {
|
|
833
|
+
name: "sixty_five?",
|
|
834
|
+
description: "returns whether the integer is sixty five.",
|
|
835
|
+
examples: %w[65.sixty_five? 66.sixty_five? 0.sixty_five?]
|
|
836
|
+
},
|
|
837
|
+
"sixty_six?" => {
|
|
838
|
+
name: "sixty_six?",
|
|
839
|
+
description: "returns whether the integer is sixty six.",
|
|
840
|
+
examples: %w[66.sixty_six? 67.sixty_six? 0.sixty_six?]
|
|
841
|
+
},
|
|
842
|
+
"sixty_seven?" => {
|
|
843
|
+
name: "sixty_seven?",
|
|
844
|
+
description: "returns whether the integer is sixty seven.",
|
|
845
|
+
examples: %w[67.sixty_seven? 68.sixty_seven? 0.sixty_seven?]
|
|
846
|
+
},
|
|
847
|
+
"sixty_eight?" => {
|
|
848
|
+
name: "sixty_eight?",
|
|
849
|
+
description: "returns whether the integer is sixty eight.",
|
|
850
|
+
examples: %w[68.sixty_eight? 69.sixty_eight? 0.sixty_eight?]
|
|
851
|
+
},
|
|
852
|
+
"sixty_nine?" => {
|
|
853
|
+
name: "sixty_nine?",
|
|
854
|
+
description: "returns whether the integer is sixty nine.",
|
|
855
|
+
examples: %w[69.sixty_nine? 70.sixty_nine? 0.sixty_nine?]
|
|
856
|
+
},
|
|
857
|
+
"seventy?" => {
|
|
858
|
+
name: "seventy?",
|
|
859
|
+
description: "returns whether the integer is seventy.",
|
|
860
|
+
examples: %w[70.seventy? 71.seventy? 0.seventy?]
|
|
861
|
+
},
|
|
862
|
+
"seventy_one?" => {
|
|
863
|
+
name: "seventy_one?",
|
|
864
|
+
description: "returns whether the integer is seventy one.",
|
|
865
|
+
examples: %w[71.seventy_one? 72.seventy_one? 0.seventy_one?]
|
|
866
|
+
},
|
|
867
|
+
"seventy_two?" => {
|
|
868
|
+
name: "seventy_two?",
|
|
869
|
+
description: "returns whether the integer is seventy two.",
|
|
870
|
+
examples: %w[72.seventy_two? 73.seventy_two? 0.seventy_two?]
|
|
871
|
+
},
|
|
872
|
+
"seventy_three?" => {
|
|
873
|
+
name: "seventy_three?",
|
|
874
|
+
description: "returns whether the integer is seventy three.",
|
|
875
|
+
examples: %w[73.seventy_three? 74.seventy_three? 0.seventy_three?]
|
|
876
|
+
},
|
|
877
|
+
"seventy_four?" => {
|
|
878
|
+
name: "seventy_four?",
|
|
879
|
+
description: "returns whether the integer is seventy four.",
|
|
880
|
+
examples: %w[74.seventy_four? 75.seventy_four? 0.seventy_four?]
|
|
881
|
+
},
|
|
882
|
+
"seventy_five?" => {
|
|
883
|
+
name: "seventy_five?",
|
|
884
|
+
description: "returns whether the integer is seventy five.",
|
|
885
|
+
examples: %w[75.seventy_five? 76.seventy_five? 0.seventy_five?]
|
|
886
|
+
},
|
|
887
|
+
"seventy_six?" => {
|
|
888
|
+
name: "seventy_six?",
|
|
889
|
+
description: "returns whether the integer is seventy six.",
|
|
890
|
+
examples: %w[76.seventy_six? 77.seventy_six? 0.seventy_six?]
|
|
891
|
+
},
|
|
892
|
+
"seventy_seven?" => {
|
|
893
|
+
name: "seventy_seven?",
|
|
894
|
+
description: "returns whether the integer is seventy seven.",
|
|
895
|
+
examples: %w[77.seventy_seven? 78.seventy_seven? 0.seventy_seven?]
|
|
896
|
+
},
|
|
897
|
+
"seventy_eight?" => {
|
|
898
|
+
name: "seventy_eight?",
|
|
899
|
+
description: "returns whether the integer is seventy eight.",
|
|
900
|
+
examples: %w[78.seventy_eight? 79.seventy_eight? 0.seventy_eight?]
|
|
901
|
+
},
|
|
902
|
+
"seventy_nine?" => {
|
|
903
|
+
name: "seventy_nine?",
|
|
904
|
+
description: "returns whether the integer is seventy nine.",
|
|
905
|
+
examples: %w[79.seventy_nine? 80.seventy_nine? 0.seventy_nine?]
|
|
906
|
+
},
|
|
907
|
+
"eighty?" => {
|
|
908
|
+
name: "eighty?",
|
|
909
|
+
description: "returns whether the integer is eighty.",
|
|
910
|
+
examples: %w[80.eighty? 81.eighty? 0.eighty?]
|
|
911
|
+
},
|
|
912
|
+
"eighty_one?" => {
|
|
913
|
+
name: "eighty_one?",
|
|
914
|
+
description: "returns whether the integer is eighty one.",
|
|
915
|
+
examples: %w[81.eighty_one? 82.eighty_one? 0.eighty_one?]
|
|
916
|
+
},
|
|
917
|
+
"eighty_two?" => {
|
|
918
|
+
name: "eighty_two?",
|
|
919
|
+
description: "returns whether the integer is eighty two.",
|
|
920
|
+
examples: %w[82.eighty_two? 83.eighty_two? 0.eighty_two?]
|
|
921
|
+
},
|
|
922
|
+
"eighty_three?" => {
|
|
923
|
+
name: "eighty_three?",
|
|
924
|
+
description: "returns whether the integer is eighty three.",
|
|
925
|
+
examples: %w[83.eighty_three? 84.eighty_three? 0.eighty_three?]
|
|
926
|
+
},
|
|
927
|
+
"eighty_four?" => {
|
|
928
|
+
name: "eighty_four?",
|
|
929
|
+
description: "returns whether the integer is eighty four.",
|
|
930
|
+
examples: %w[84.eighty_four? 85.eighty_four? 0.eighty_four?]
|
|
931
|
+
},
|
|
932
|
+
"eighty_five?" => {
|
|
933
|
+
name: "eighty_five?",
|
|
934
|
+
description: "returns whether the integer is eighty five.",
|
|
935
|
+
examples: %w[85.eighty_five? 86.eighty_five? 0.eighty_five?]
|
|
936
|
+
},
|
|
937
|
+
"eighty_six?" => {
|
|
938
|
+
name: "eighty_six?",
|
|
939
|
+
description: "returns whether the integer is eighty six.",
|
|
940
|
+
examples: %w[86.eighty_six? 87.eighty_six? 0.eighty_six?]
|
|
941
|
+
},
|
|
942
|
+
"eighty_seven?" => {
|
|
943
|
+
name: "eighty_seven?",
|
|
944
|
+
description: "returns whether the integer is eighty seven.",
|
|
945
|
+
examples: %w[87.eighty_seven? 88.eighty_seven? 0.eighty_seven?]
|
|
946
|
+
},
|
|
947
|
+
"eighty_eight?" => {
|
|
948
|
+
name: "eighty_eight?",
|
|
949
|
+
description: "returns whether the integer is eighty eight.",
|
|
950
|
+
examples: %w[88.eighty_eight? 89.eighty_eight? 0.eighty_eight?]
|
|
951
|
+
},
|
|
952
|
+
"eighty_nine?" => {
|
|
953
|
+
name: "eighty_nine?",
|
|
954
|
+
description: "returns whether the integer is eighty nine.",
|
|
955
|
+
examples: %w[89.eighty_nine? 90.eighty_nine? 0.eighty_nine?]
|
|
956
|
+
},
|
|
957
|
+
"ninety?" => {
|
|
958
|
+
name: "ninety?",
|
|
959
|
+
description: "returns whether the integer is ninety.",
|
|
960
|
+
examples: %w[90.ninety? 91.ninety? 0.ninety?]
|
|
961
|
+
},
|
|
962
|
+
"ninety_one?" => {
|
|
963
|
+
name: "ninety_one?",
|
|
964
|
+
description: "returns whether the integer is ninety one.",
|
|
965
|
+
examples: %w[91.ninety_one? 92.ninety_one? 0.ninety_one?]
|
|
966
|
+
},
|
|
967
|
+
"ninety_two?" => {
|
|
968
|
+
name: "ninety_two?",
|
|
969
|
+
description: "returns whether the integer is ninety two.",
|
|
970
|
+
examples: %w[92.ninety_two? 93.ninety_two? 0.ninety_two?]
|
|
971
|
+
},
|
|
972
|
+
"ninety_three?" => {
|
|
973
|
+
name: "ninety_three?",
|
|
974
|
+
description: "returns whether the integer is ninety three.",
|
|
975
|
+
examples: %w[93.ninety_three? 94.ninety_three? 0.ninety_three?]
|
|
976
|
+
},
|
|
977
|
+
"ninety_four?" => {
|
|
978
|
+
name: "ninety_four?",
|
|
979
|
+
description: "returns whether the integer is ninety four.",
|
|
980
|
+
examples: %w[94.ninety_four? 95.ninety_four? 0.ninety_four?]
|
|
981
|
+
},
|
|
982
|
+
"ninety_five?" => {
|
|
983
|
+
name: "ninety_five?",
|
|
984
|
+
description: "returns whether the integer is ninety five.",
|
|
985
|
+
examples: %w[95.ninety_five? 96.ninety_five? 0.ninety_five?]
|
|
986
|
+
},
|
|
987
|
+
"ninety_six?" => {
|
|
988
|
+
name: "ninety_six?",
|
|
989
|
+
description: "returns whether the integer is ninety six.",
|
|
990
|
+
examples: %w[96.ninety_six? 97.ninety_six? 0.ninety_six?]
|
|
991
|
+
},
|
|
992
|
+
"ninety_seven?" => {
|
|
993
|
+
name: "ninety_seven?",
|
|
994
|
+
description: "returns whether the integer is ninety seven.",
|
|
995
|
+
examples: %w[97.ninety_seven? 98.ninety_seven? 0.ninety_seven?]
|
|
996
|
+
},
|
|
997
|
+
"ninety_eight?" => {
|
|
998
|
+
name: "ninety_eight?",
|
|
999
|
+
description: "returns whether the integer is ninety eight.",
|
|
1000
|
+
examples: %w[98.ninety_eight? 99.ninety_eight? 0.ninety_eight?]
|
|
1001
|
+
},
|
|
1002
|
+
"ninety_nine?" => {
|
|
1003
|
+
name: "ninety_nine?",
|
|
1004
|
+
description: "returns whether the integer is ninety nine.",
|
|
1005
|
+
examples: %w[99.ninety_nine? 100.ninety_nine? 0.ninety_nine?]
|
|
1006
|
+
},
|
|
1007
|
+
"one_hundred?" => {
|
|
1008
|
+
name: "one_hundred?",
|
|
1009
|
+
description: "returns whether the integer is one hundred.",
|
|
1010
|
+
examples: %w[100.one_hundred? 101.one_hundred? 0.one_hundred?]
|
|
1011
|
+
}
|
|
1012
|
+
}.freeze
|
|
1013
|
+
|
|
1014
|
+
def self.function_documentation(scope)
|
|
1015
|
+
return INSTANCE_FUNCTIONS if scope == :instance
|
|
1016
|
+
|
|
1017
|
+
{}
|
|
1018
|
+
end
|
|
1019
|
+
|
|
6
1020
|
def initialize(*args, **_kargs, &_block)
|
|
7
1021
|
self.raw =
|
|
8
1022
|
if args.first.class.in?(NUMBER_CLASSES)
|
|
@@ -37,6 +1051,9 @@ class Code
|
|
|
37
1051
|
when "**", "power"
|
|
38
1052
|
sig(args) { Integer | Decimal }
|
|
39
1053
|
code_power(code_value)
|
|
1054
|
+
when "power_modulo"
|
|
1055
|
+
sig(args) { [Integer, Integer] }
|
|
1056
|
+
code_power_modulo(*code_arguments.raw)
|
|
40
1057
|
when "+", "plus"
|
|
41
1058
|
sig(args) { Object.maybe }
|
|
42
1059
|
code_arguments.any? ? code_plus(code_value) : code_self
|
|
@@ -46,6 +1063,39 @@ class Code
|
|
|
46
1063
|
when "/", "division", "÷"
|
|
47
1064
|
sig(args) { Integer | Decimal }
|
|
48
1065
|
code_division(code_value)
|
|
1066
|
+
when "divide"
|
|
1067
|
+
sig(args) { Integer | Decimal }
|
|
1068
|
+
code_divide(code_value)
|
|
1069
|
+
when "divide_modulo"
|
|
1070
|
+
sig(args) { Integer | Decimal }
|
|
1071
|
+
code_divide_modulo(code_value)
|
|
1072
|
+
when "decimal_divide"
|
|
1073
|
+
sig(args) { Integer | Decimal }
|
|
1074
|
+
code_decimal_divide(code_value)
|
|
1075
|
+
when "digits"
|
|
1076
|
+
sig(args) { Integer.maybe }
|
|
1077
|
+
code_digits(code_value)
|
|
1078
|
+
when "bit_length"
|
|
1079
|
+
sig(args)
|
|
1080
|
+
code_bit_length
|
|
1081
|
+
when "all_bits?"
|
|
1082
|
+
sig(args) { Integer }
|
|
1083
|
+
code_all_bits?(code_value)
|
|
1084
|
+
when "any_bits?"
|
|
1085
|
+
sig(args) { Integer }
|
|
1086
|
+
code_any_bits?(code_value)
|
|
1087
|
+
when "no_bits?"
|
|
1088
|
+
sig(args) { Integer }
|
|
1089
|
+
code_no_bits?(code_value)
|
|
1090
|
+
when "character"
|
|
1091
|
+
sig(args)
|
|
1092
|
+
code_character
|
|
1093
|
+
when "greatest_common_denominator"
|
|
1094
|
+
sig(args) { Integer }
|
|
1095
|
+
code_greatest_common_denominator(code_value)
|
|
1096
|
+
when "lowest_common_multiple"
|
|
1097
|
+
sig(args) { Integer }
|
|
1098
|
+
code_lowest_common_multiple(code_value)
|
|
49
1099
|
when "<<", "left_shift"
|
|
50
1100
|
sig(args) { Integer | Decimal }
|
|
51
1101
|
code_left_shift(code_value)
|
|
@@ -58,9 +1108,18 @@ class Code
|
|
|
58
1108
|
when "abs"
|
|
59
1109
|
sig(args)
|
|
60
1110
|
code_abs
|
|
1111
|
+
when "between?"
|
|
1112
|
+
sig(args) { [Integer | Decimal, Integer | Decimal] }
|
|
1113
|
+
code_between?(*code_arguments.raw)
|
|
61
1114
|
when "ceil"
|
|
62
1115
|
sig(args) { Integer.maybe }
|
|
63
1116
|
code_ceil(code_value)
|
|
1117
|
+
when "ceil_divide"
|
|
1118
|
+
sig(args) { Integer | Decimal }
|
|
1119
|
+
code_ceil_divide(code_value)
|
|
1120
|
+
when "clamp"
|
|
1121
|
+
sig(args) { [Integer | Decimal, Integer | Decimal] }
|
|
1122
|
+
code_clamp(*code_arguments.raw)
|
|
64
1123
|
when "day", "days"
|
|
65
1124
|
sig(args)
|
|
66
1125
|
code_days
|
|
@@ -88,18 +1147,48 @@ class Code
|
|
|
88
1147
|
when "odd?"
|
|
89
1148
|
sig(args)
|
|
90
1149
|
code_odd?
|
|
1150
|
+
when "minute", "minutes"
|
|
1151
|
+
sig(args)
|
|
1152
|
+
code_minutes
|
|
1153
|
+
when "month", "months"
|
|
1154
|
+
sig(args)
|
|
1155
|
+
code_months
|
|
1156
|
+
when "next", "successor"
|
|
1157
|
+
sig(args)
|
|
1158
|
+
code_next
|
|
1159
|
+
when "previous", "predecessor"
|
|
1160
|
+
sig(args)
|
|
1161
|
+
code_previous
|
|
1162
|
+
when "remainder"
|
|
1163
|
+
sig(args) { Integer | Decimal }
|
|
1164
|
+
code_remainder(code_value)
|
|
91
1165
|
when "round"
|
|
92
1166
|
sig(args) { Integer.maybe }
|
|
93
1167
|
code_round(code_value)
|
|
1168
|
+
when "second", "seconds"
|
|
1169
|
+
sig(args)
|
|
1170
|
+
code_seconds
|
|
94
1171
|
when "sqrt"
|
|
95
1172
|
sig(args)
|
|
96
1173
|
code_sqrt
|
|
97
1174
|
when "times"
|
|
98
1175
|
sig(args) { Function }
|
|
99
1176
|
code_times(code_value, **globals)
|
|
1177
|
+
when "down_to"
|
|
1178
|
+
sig(args) { [Integer, Function] }
|
|
1179
|
+
code_down_to(*code_arguments.raw, **globals)
|
|
1180
|
+
when "up_to"
|
|
1181
|
+
sig(args) { [Integer, Function] }
|
|
1182
|
+
code_up_to(*code_arguments.raw, **globals)
|
|
100
1183
|
when "truncate"
|
|
101
1184
|
sig(args) { Integer.maybe }
|
|
102
1185
|
code_truncate(code_value)
|
|
1186
|
+
when "week", "weeks"
|
|
1187
|
+
sig(args)
|
|
1188
|
+
code_weeks
|
|
1189
|
+
when "year", "years"
|
|
1190
|
+
sig(args)
|
|
1191
|
+
code_years
|
|
103
1192
|
when "|", "bitwise_or"
|
|
104
1193
|
sig(args) { Integer | Decimal }
|
|
105
1194
|
code_bitwise_or(code_value)
|
|
@@ -115,6 +1204,27 @@ class Code
|
|
|
115
1204
|
when "negative?"
|
|
116
1205
|
sig(args)
|
|
117
1206
|
code_negative?
|
|
1207
|
+
when "non_zero?"
|
|
1208
|
+
sig(args)
|
|
1209
|
+
code_non_zero?
|
|
1210
|
+
when "integer?"
|
|
1211
|
+
sig(args)
|
|
1212
|
+
code_integer?
|
|
1213
|
+
when "finite?"
|
|
1214
|
+
sig(args)
|
|
1215
|
+
code_finite?
|
|
1216
|
+
when "infinite?"
|
|
1217
|
+
sig(args)
|
|
1218
|
+
code_infinite?
|
|
1219
|
+
when "numerator"
|
|
1220
|
+
sig(args)
|
|
1221
|
+
code_numerator
|
|
1222
|
+
when "denominator"
|
|
1223
|
+
sig(args)
|
|
1224
|
+
code_denominator
|
|
1225
|
+
when "magnitude"
|
|
1226
|
+
sig(args)
|
|
1227
|
+
code_magnitude
|
|
118
1228
|
when "zero?"
|
|
119
1229
|
sig(args)
|
|
120
1230
|
code_zero?
|
|
@@ -442,12 +1552,40 @@ class Code
|
|
|
442
1552
|
Integer.new(raw ^ code_other.raw.to_i)
|
|
443
1553
|
end
|
|
444
1554
|
|
|
1555
|
+
def code_bit_length
|
|
1556
|
+
Integer.new(raw.bit_length)
|
|
1557
|
+
end
|
|
1558
|
+
|
|
1559
|
+
def code_all_bits?(mask)
|
|
1560
|
+
code_mask = mask.to_code
|
|
1561
|
+
|
|
1562
|
+
Boolean.new(raw.allbits?(code_mask.raw))
|
|
1563
|
+
end
|
|
1564
|
+
|
|
1565
|
+
def code_any_bits?(mask)
|
|
1566
|
+
code_mask = mask.to_code
|
|
1567
|
+
|
|
1568
|
+
Boolean.new(raw.anybits?(code_mask.raw))
|
|
1569
|
+
end
|
|
1570
|
+
|
|
1571
|
+
def code_no_bits?(mask)
|
|
1572
|
+
code_mask = mask.to_code
|
|
1573
|
+
|
|
1574
|
+
Boolean.new(raw.nobits?(code_mask.raw))
|
|
1575
|
+
end
|
|
1576
|
+
|
|
445
1577
|
def code_ceil(n = nil)
|
|
446
1578
|
code_n = n.to_code
|
|
447
1579
|
code_n = Integer.new(0) if code_n.nothing?
|
|
448
1580
|
Integer.new(raw.ceil(code_n.raw))
|
|
449
1581
|
end
|
|
450
1582
|
|
|
1583
|
+
def code_ceil_divide(other)
|
|
1584
|
+
code_other = other.to_code
|
|
1585
|
+
|
|
1586
|
+
Integer.new(raw.ceildiv(code_other.raw))
|
|
1587
|
+
end
|
|
1588
|
+
|
|
451
1589
|
def code_decrement!(n = nil)
|
|
452
1590
|
code_n = n.to_code
|
|
453
1591
|
code_n = Integer.new(1) if code_n.nothing?
|
|
@@ -466,6 +1604,24 @@ class Code
|
|
|
466
1604
|
Decimal.new(BigDecimal(raw) / code_other.raw)
|
|
467
1605
|
end
|
|
468
1606
|
|
|
1607
|
+
def code_decimal_divide(other)
|
|
1608
|
+
code_division(other)
|
|
1609
|
+
end
|
|
1610
|
+
|
|
1611
|
+
def code_digits(base = nil)
|
|
1612
|
+
code_base = base.to_code
|
|
1613
|
+
|
|
1614
|
+
if code_base.nothing?
|
|
1615
|
+
List.new(raw.digits)
|
|
1616
|
+
else
|
|
1617
|
+
List.new(raw.digits(code_base.raw))
|
|
1618
|
+
end
|
|
1619
|
+
end
|
|
1620
|
+
|
|
1621
|
+
def code_character
|
|
1622
|
+
String.new(raw.chr)
|
|
1623
|
+
end
|
|
1624
|
+
|
|
469
1625
|
def code_even?
|
|
470
1626
|
Boolean.new(raw.even?)
|
|
471
1627
|
end
|
|
@@ -489,6 +1645,16 @@ class Code
|
|
|
489
1645
|
Integer.new(raw + code_n.raw)
|
|
490
1646
|
end
|
|
491
1647
|
|
|
1648
|
+
def code_greatest_common_denominator(other)
|
|
1649
|
+
code_other = other.to_code
|
|
1650
|
+
Integer.new(raw.gcd(code_other.raw))
|
|
1651
|
+
end
|
|
1652
|
+
|
|
1653
|
+
def code_lowest_common_multiple(other)
|
|
1654
|
+
code_other = other.to_code
|
|
1655
|
+
Integer.new(raw.lcm(code_other.raw))
|
|
1656
|
+
end
|
|
1657
|
+
|
|
492
1658
|
def code_left_shift(other)
|
|
493
1659
|
code_other = other.to_code
|
|
494
1660
|
Integer.new(raw << code_other.raw.to_i)
|
|
@@ -546,12 +1712,19 @@ class Code
|
|
|
546
1712
|
code_other = other.to_code
|
|
547
1713
|
|
|
548
1714
|
if code_other.is_a?(Integer)
|
|
549
|
-
Integer.new(raw**
|
|
1715
|
+
Integer.new(raw**code_other.raw)
|
|
550
1716
|
else
|
|
551
|
-
Decimal.new(raw**
|
|
1717
|
+
Decimal.new(raw**code_other.raw)
|
|
552
1718
|
end
|
|
553
1719
|
end
|
|
554
1720
|
|
|
1721
|
+
def code_power_modulo(power, modulo)
|
|
1722
|
+
code_power = power.to_code
|
|
1723
|
+
code_modulo = modulo.to_code
|
|
1724
|
+
|
|
1725
|
+
Integer.new(raw.pow(code_power.raw, code_modulo.raw))
|
|
1726
|
+
end
|
|
1727
|
+
|
|
555
1728
|
def code_right_shift(other)
|
|
556
1729
|
code_other = other.to_code
|
|
557
1730
|
Integer.new(raw >> code_other.raw.to_i)
|
|
@@ -593,6 +1766,48 @@ class Code
|
|
|
593
1766
|
e.code_value
|
|
594
1767
|
end
|
|
595
1768
|
|
|
1769
|
+
def code_down_to(value, function, **globals)
|
|
1770
|
+
code_value = value.to_code
|
|
1771
|
+
code_function = function.to_code
|
|
1772
|
+
|
|
1773
|
+
raw
|
|
1774
|
+
.downto(code_value.raw)
|
|
1775
|
+
.with_index do |element, index|
|
|
1776
|
+
code_function.call(
|
|
1777
|
+
arguments:
|
|
1778
|
+
List.new([Integer.new(element), Integer.new(index), self]),
|
|
1779
|
+
**globals
|
|
1780
|
+
)
|
|
1781
|
+
rescue Error::Next => e
|
|
1782
|
+
e.code_value
|
|
1783
|
+
end
|
|
1784
|
+
|
|
1785
|
+
self
|
|
1786
|
+
rescue Error::Break => e
|
|
1787
|
+
e.code_value
|
|
1788
|
+
end
|
|
1789
|
+
|
|
1790
|
+
def code_up_to(value, function, **globals)
|
|
1791
|
+
code_value = value.to_code
|
|
1792
|
+
code_function = function.to_code
|
|
1793
|
+
|
|
1794
|
+
raw
|
|
1795
|
+
.upto(code_value.raw)
|
|
1796
|
+
.with_index do |element, index|
|
|
1797
|
+
code_function.call(
|
|
1798
|
+
arguments:
|
|
1799
|
+
List.new([Integer.new(element), Integer.new(index), self]),
|
|
1800
|
+
**globals
|
|
1801
|
+
)
|
|
1802
|
+
rescue Error::Next => e
|
|
1803
|
+
e.code_value
|
|
1804
|
+
end
|
|
1805
|
+
|
|
1806
|
+
self
|
|
1807
|
+
rescue Error::Break => e
|
|
1808
|
+
e.code_value
|
|
1809
|
+
end
|
|
1810
|
+
|
|
596
1811
|
def code_truncate(n = nil)
|
|
597
1812
|
code_n = n.to_code
|
|
598
1813
|
code_n = Integer.new(0) if code_n.nothing?
|
|
@@ -616,6 +1831,26 @@ class Code
|
|
|
616
1831
|
Duration.new(raw.hours)
|
|
617
1832
|
end
|
|
618
1833
|
|
|
1834
|
+
def code_minutes
|
|
1835
|
+
Duration.new(raw.minutes)
|
|
1836
|
+
end
|
|
1837
|
+
|
|
1838
|
+
def code_months
|
|
1839
|
+
Duration.new(raw.months)
|
|
1840
|
+
end
|
|
1841
|
+
|
|
1842
|
+
def code_seconds
|
|
1843
|
+
Duration.new(raw.seconds)
|
|
1844
|
+
end
|
|
1845
|
+
|
|
1846
|
+
def code_weeks
|
|
1847
|
+
Duration.new(raw.weeks)
|
|
1848
|
+
end
|
|
1849
|
+
|
|
1850
|
+
def code_years
|
|
1851
|
+
Duration.new(raw.years)
|
|
1852
|
+
end
|
|
1853
|
+
|
|
619
1854
|
def code_days
|
|
620
1855
|
Duration.new(raw.days)
|
|
621
1856
|
end
|
|
@@ -628,6 +1863,34 @@ class Code
|
|
|
628
1863
|
Boolean.new(raw.negative?)
|
|
629
1864
|
end
|
|
630
1865
|
|
|
1866
|
+
def code_non_zero?
|
|
1867
|
+
Boolean.new(!raw.zero?)
|
|
1868
|
+
end
|
|
1869
|
+
|
|
1870
|
+
def code_integer?
|
|
1871
|
+
Boolean.new(true)
|
|
1872
|
+
end
|
|
1873
|
+
|
|
1874
|
+
def code_finite?
|
|
1875
|
+
Boolean.new(true)
|
|
1876
|
+
end
|
|
1877
|
+
|
|
1878
|
+
def code_infinite?
|
|
1879
|
+
Boolean.new(false)
|
|
1880
|
+
end
|
|
1881
|
+
|
|
1882
|
+
def code_numerator
|
|
1883
|
+
Integer.new(raw.numerator)
|
|
1884
|
+
end
|
|
1885
|
+
|
|
1886
|
+
def code_denominator
|
|
1887
|
+
Integer.new(raw.denominator)
|
|
1888
|
+
end
|
|
1889
|
+
|
|
1890
|
+
def code_magnitude
|
|
1891
|
+
code_abs
|
|
1892
|
+
end
|
|
1893
|
+
|
|
631
1894
|
def code_zero?
|
|
632
1895
|
Boolean.new(raw.zero?)
|
|
633
1896
|
end
|