rbs 0.2.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 +7 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +15 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +9 -0
- data/COPYING +56 -0
- data/Gemfile +6 -0
- data/README.md +93 -0
- data/Rakefile +142 -0
- data/bin/annotate-with-rdoc +157 -0
- data/bin/console +14 -0
- data/bin/query-rdoc +103 -0
- data/bin/setup +10 -0
- data/bin/sort +89 -0
- data/bin/test_runner.rb +16 -0
- data/docs/CONTRIBUTING.md +97 -0
- data/docs/sigs.md +148 -0
- data/docs/stdlib.md +152 -0
- data/docs/syntax.md +528 -0
- data/exe/rbs +7 -0
- data/lib/rbs.rb +64 -0
- data/lib/rbs/ast/annotation.rb +27 -0
- data/lib/rbs/ast/comment.rb +27 -0
- data/lib/rbs/ast/declarations.rb +395 -0
- data/lib/rbs/ast/members.rb +362 -0
- data/lib/rbs/buffer.rb +50 -0
- data/lib/rbs/builtin_names.rb +55 -0
- data/lib/rbs/cli.rb +558 -0
- data/lib/rbs/constant.rb +26 -0
- data/lib/rbs/constant_table.rb +150 -0
- data/lib/rbs/definition.rb +170 -0
- data/lib/rbs/definition_builder.rb +919 -0
- data/lib/rbs/environment.rb +281 -0
- data/lib/rbs/environment_loader.rb +136 -0
- data/lib/rbs/environment_walker.rb +124 -0
- data/lib/rbs/errors.rb +187 -0
- data/lib/rbs/location.rb +102 -0
- data/lib/rbs/method_type.rb +123 -0
- data/lib/rbs/namespace.rb +91 -0
- data/lib/rbs/parser.y +1344 -0
- data/lib/rbs/prototype/rb.rb +553 -0
- data/lib/rbs/prototype/rbi.rb +587 -0
- data/lib/rbs/prototype/runtime.rb +381 -0
- data/lib/rbs/substitution.rb +46 -0
- data/lib/rbs/test.rb +26 -0
- data/lib/rbs/test/errors.rb +61 -0
- data/lib/rbs/test/hook.rb +294 -0
- data/lib/rbs/test/setup.rb +58 -0
- data/lib/rbs/test/spy.rb +325 -0
- data/lib/rbs/test/test_helper.rb +183 -0
- data/lib/rbs/test/type_check.rb +254 -0
- data/lib/rbs/type_name.rb +70 -0
- data/lib/rbs/types.rb +936 -0
- data/lib/rbs/variance_calculator.rb +138 -0
- data/lib/rbs/vendorer.rb +47 -0
- data/lib/rbs/version.rb +3 -0
- data/lib/rbs/writer.rb +269 -0
- data/lib/ruby/signature.rb +7 -0
- data/rbs.gemspec +46 -0
- data/stdlib/abbrev/abbrev.rbs +60 -0
- data/stdlib/base64/base64.rbs +71 -0
- data/stdlib/benchmark/benchmark.rbs +372 -0
- data/stdlib/builtin/array.rbs +1997 -0
- data/stdlib/builtin/basic_object.rbs +280 -0
- data/stdlib/builtin/binding.rbs +177 -0
- data/stdlib/builtin/builtin.rbs +45 -0
- data/stdlib/builtin/class.rbs +145 -0
- data/stdlib/builtin/comparable.rbs +116 -0
- data/stdlib/builtin/complex.rbs +400 -0
- data/stdlib/builtin/constants.rbs +37 -0
- data/stdlib/builtin/data.rbs +5 -0
- data/stdlib/builtin/deprecated.rbs +2 -0
- data/stdlib/builtin/dir.rbs +413 -0
- data/stdlib/builtin/encoding.rbs +607 -0
- data/stdlib/builtin/enumerable.rbs +404 -0
- data/stdlib/builtin/enumerator.rbs +260 -0
- data/stdlib/builtin/errno.rbs +781 -0
- data/stdlib/builtin/errors.rbs +582 -0
- data/stdlib/builtin/exception.rbs +194 -0
- data/stdlib/builtin/false_class.rbs +40 -0
- data/stdlib/builtin/fiber.rbs +68 -0
- data/stdlib/builtin/fiber_error.rbs +12 -0
- data/stdlib/builtin/file.rbs +1076 -0
- data/stdlib/builtin/file_test.rbs +59 -0
- data/stdlib/builtin/float.rbs +696 -0
- data/stdlib/builtin/gc.rbs +243 -0
- data/stdlib/builtin/hash.rbs +1029 -0
- data/stdlib/builtin/integer.rbs +707 -0
- data/stdlib/builtin/io.rbs +683 -0
- data/stdlib/builtin/kernel.rbs +576 -0
- data/stdlib/builtin/marshal.rbs +161 -0
- data/stdlib/builtin/match_data.rbs +271 -0
- data/stdlib/builtin/math.rbs +369 -0
- data/stdlib/builtin/method.rbs +185 -0
- data/stdlib/builtin/module.rbs +1104 -0
- data/stdlib/builtin/nil_class.rbs +82 -0
- data/stdlib/builtin/numeric.rbs +409 -0
- data/stdlib/builtin/object.rbs +824 -0
- data/stdlib/builtin/proc.rbs +429 -0
- data/stdlib/builtin/process.rbs +1227 -0
- data/stdlib/builtin/random.rbs +267 -0
- data/stdlib/builtin/range.rbs +226 -0
- data/stdlib/builtin/rational.rbs +424 -0
- data/stdlib/builtin/rb_config.rbs +57 -0
- data/stdlib/builtin/regexp.rbs +1083 -0
- data/stdlib/builtin/ruby_vm.rbs +14 -0
- data/stdlib/builtin/signal.rbs +55 -0
- data/stdlib/builtin/string.rbs +1901 -0
- data/stdlib/builtin/string_io.rbs +284 -0
- data/stdlib/builtin/struct.rbs +40 -0
- data/stdlib/builtin/symbol.rbs +228 -0
- data/stdlib/builtin/thread.rbs +1108 -0
- data/stdlib/builtin/thread_group.rbs +23 -0
- data/stdlib/builtin/time.rbs +1047 -0
- data/stdlib/builtin/trace_point.rbs +290 -0
- data/stdlib/builtin/true_class.rbs +46 -0
- data/stdlib/builtin/unbound_method.rbs +153 -0
- data/stdlib/builtin/warning.rbs +17 -0
- data/stdlib/coverage/coverage.rbs +62 -0
- data/stdlib/csv/csv.rbs +773 -0
- data/stdlib/erb/erb.rbs +392 -0
- data/stdlib/find/find.rbs +40 -0
- data/stdlib/ipaddr/ipaddr.rbs +247 -0
- data/stdlib/json/json.rbs +335 -0
- data/stdlib/pathname/pathname.rbs +1093 -0
- data/stdlib/prime/integer-extension.rbs +23 -0
- data/stdlib/prime/prime.rbs +188 -0
- data/stdlib/securerandom/securerandom.rbs +9 -0
- data/stdlib/set/set.rbs +301 -0
- data/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +292 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
# A rational number can be represented as a pair of integer numbers: a/b (b>0),
|
|
2
|
+
# where a is the numerator and b is the denominator. Integer a equals rational
|
|
3
|
+
# a/1 mathematically.
|
|
4
|
+
#
|
|
5
|
+
# In Ruby, you can create rational objects with the Kernel#Rational, to_r, or
|
|
6
|
+
# rationalize methods or by suffixing `r` to a literal. The return values will
|
|
7
|
+
# be irreducible fractions.
|
|
8
|
+
#
|
|
9
|
+
# Rational(1) #=> (1/1)
|
|
10
|
+
# Rational(2, 3) #=> (2/3)
|
|
11
|
+
# Rational(4, -6) #=> (-2/3)
|
|
12
|
+
# 3.to_r #=> (3/1)
|
|
13
|
+
# 2/3r #=> (2/3)
|
|
14
|
+
#
|
|
15
|
+
# You can also create rational objects from floating-point numbers or strings.
|
|
16
|
+
#
|
|
17
|
+
# Rational(0.3) #=> (5404319552844595/18014398509481984)
|
|
18
|
+
# Rational('0.3') #=> (3/10)
|
|
19
|
+
# Rational('2/3') #=> (2/3)
|
|
20
|
+
#
|
|
21
|
+
# 0.3.to_r #=> (5404319552844595/18014398509481984)
|
|
22
|
+
# '0.3'.to_r #=> (3/10)
|
|
23
|
+
# '2/3'.to_r #=> (2/3)
|
|
24
|
+
# 0.3.rationalize #=> (3/10)
|
|
25
|
+
#
|
|
26
|
+
# A rational object is an exact number, which helps you to write programs
|
|
27
|
+
# without any rounding errors.
|
|
28
|
+
#
|
|
29
|
+
# 10.times.inject(0) {|t| t + 0.1 } #=> 0.9999999999999999
|
|
30
|
+
# 10.times.inject(0) {|t| t + Rational('0.1') } #=> (1/1)
|
|
31
|
+
#
|
|
32
|
+
# However, when an expression includes an inexact component (numerical value or
|
|
33
|
+
# operation), it will produce an inexact result.
|
|
34
|
+
#
|
|
35
|
+
# Rational(10) / 3 #=> (10/3)
|
|
36
|
+
# Rational(10) / 3.0 #=> 3.3333333333333335
|
|
37
|
+
#
|
|
38
|
+
# Rational(-8) ** Rational(1, 3)
|
|
39
|
+
# #=> (1.0000000000000002+1.7320508075688772i)
|
|
40
|
+
#
|
|
41
|
+
class Rational < Numeric
|
|
42
|
+
public
|
|
43
|
+
|
|
44
|
+
def %: (Integer) -> Rational
|
|
45
|
+
| (Float) -> Float
|
|
46
|
+
| (Rational) -> Rational
|
|
47
|
+
| (Numeric) -> Numeric
|
|
48
|
+
|
|
49
|
+
# Performs multiplication.
|
|
50
|
+
#
|
|
51
|
+
# Rational(2, 3) * Rational(2, 3) #=> (4/9)
|
|
52
|
+
# Rational(900) * Rational(1) #=> (900/1)
|
|
53
|
+
# Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
|
|
54
|
+
# Rational(9, 8) * 4 #=> (9/2)
|
|
55
|
+
# Rational(20, 9) * 9.8 #=> 21.77777777777778
|
|
56
|
+
#
|
|
57
|
+
def *: (Float) -> Float
|
|
58
|
+
| (Complex) -> Complex
|
|
59
|
+
| (Numeric) -> Numeric
|
|
60
|
+
|
|
61
|
+
# Performs exponentiation.
|
|
62
|
+
#
|
|
63
|
+
# Rational(2) ** Rational(3) #=> (8/1)
|
|
64
|
+
# Rational(10) ** -2 #=> (1/100)
|
|
65
|
+
# Rational(10) ** -2.0 #=> 0.01
|
|
66
|
+
# Rational(-4) ** Rational(1, 2) #=> (0.0+2.0i)
|
|
67
|
+
# Rational(1, 2) ** 0 #=> (1/1)
|
|
68
|
+
# Rational(1, 2) ** 0.0 #=> 1.0
|
|
69
|
+
#
|
|
70
|
+
def **: (Complex) -> Complex
|
|
71
|
+
| (Numeric) -> Numeric
|
|
72
|
+
|
|
73
|
+
# Performs addition.
|
|
74
|
+
#
|
|
75
|
+
# Rational(2, 3) + Rational(2, 3) #=> (4/3)
|
|
76
|
+
# Rational(900) + Rational(1) #=> (901/1)
|
|
77
|
+
# Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
|
|
78
|
+
# Rational(9, 8) + 4 #=> (41/8)
|
|
79
|
+
# Rational(20, 9) + 9.8 #=> 12.022222222222222
|
|
80
|
+
#
|
|
81
|
+
def +: (Float) -> Float
|
|
82
|
+
| (Complex) -> Complex
|
|
83
|
+
| (Numeric) -> Rational
|
|
84
|
+
|
|
85
|
+
def +@: () -> Rational
|
|
86
|
+
|
|
87
|
+
# Performs subtraction.
|
|
88
|
+
#
|
|
89
|
+
# Rational(2, 3) - Rational(2, 3) #=> (0/1)
|
|
90
|
+
# Rational(900) - Rational(1) #=> (899/1)
|
|
91
|
+
# Rational(-2, 9) - Rational(-9, 2) #=> (77/18)
|
|
92
|
+
# Rational(9, 8) - 4 #=> (-23/8)
|
|
93
|
+
# Rational(20, 9) - 9.8 #=> -7.577777777777778
|
|
94
|
+
#
|
|
95
|
+
def -: (Float) -> Float
|
|
96
|
+
| (Complex) -> Complex
|
|
97
|
+
| (Numeric) -> Rational
|
|
98
|
+
|
|
99
|
+
# Negates `rat`.
|
|
100
|
+
#
|
|
101
|
+
def -@: () -> Rational
|
|
102
|
+
|
|
103
|
+
# Performs division.
|
|
104
|
+
#
|
|
105
|
+
# Rational(2, 3) / Rational(2, 3) #=> (1/1)
|
|
106
|
+
# Rational(900) / Rational(1) #=> (900/1)
|
|
107
|
+
# Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
|
|
108
|
+
# Rational(9, 8) / 4 #=> (9/32)
|
|
109
|
+
# Rational(20, 9) / 9.8 #=> 0.22675736961451246
|
|
110
|
+
#
|
|
111
|
+
def /: (Float) -> Float
|
|
112
|
+
| (Complex) -> Complex
|
|
113
|
+
| (Numeric) -> Rational
|
|
114
|
+
|
|
115
|
+
# Returns -1, 0, or +1 depending on whether `rational` is less than, equal to,
|
|
116
|
+
# or greater than `numeric`.
|
|
117
|
+
#
|
|
118
|
+
# `nil` is returned if the two values are incomparable.
|
|
119
|
+
#
|
|
120
|
+
# Rational(2, 3) <=> Rational(2, 3) #=> 0
|
|
121
|
+
# Rational(5) <=> 5 #=> 0
|
|
122
|
+
# Rational(2, 3) <=> Rational(1, 3) #=> 1
|
|
123
|
+
# Rational(1, 3) <=> 1 #=> -1
|
|
124
|
+
# Rational(1, 3) <=> 0.3 #=> 1
|
|
125
|
+
#
|
|
126
|
+
# Rational(1, 3) <=> "0.3" #=> nil
|
|
127
|
+
#
|
|
128
|
+
def <=>: (Numeric) -> Integer?
|
|
129
|
+
|
|
130
|
+
# Returns `true` if `rat` equals `object` numerically.
|
|
131
|
+
#
|
|
132
|
+
# Rational(2, 3) == Rational(2, 3) #=> true
|
|
133
|
+
# Rational(5) == 5 #=> true
|
|
134
|
+
# Rational(0) == 0.0 #=> true
|
|
135
|
+
# Rational('1/3') == 0.33 #=> false
|
|
136
|
+
# Rational('1/2') == '1/2' #=> false
|
|
137
|
+
#
|
|
138
|
+
def ==: (untyped) -> bool
|
|
139
|
+
|
|
140
|
+
# Returns the absolute value of `rat`.
|
|
141
|
+
#
|
|
142
|
+
# (1/2r).abs #=> (1/2)
|
|
143
|
+
# (-1/2r).abs #=> (1/2)
|
|
144
|
+
#
|
|
145
|
+
# Rational#magnitude is an alias for Rational#abs.
|
|
146
|
+
#
|
|
147
|
+
def abs: () -> Rational
|
|
148
|
+
|
|
149
|
+
def abs2: () -> Rational
|
|
150
|
+
|
|
151
|
+
def angle: () -> (Integer | Float)
|
|
152
|
+
|
|
153
|
+
alias arg angle
|
|
154
|
+
|
|
155
|
+
# Returns the smallest number greater than or equal to `rat` with a precision of
|
|
156
|
+
# `ndigits` decimal digits (default: 0).
|
|
157
|
+
#
|
|
158
|
+
# When the precision is negative, the returned value is an integer with at least
|
|
159
|
+
# `ndigits.abs` trailing zeros.
|
|
160
|
+
#
|
|
161
|
+
# Returns a rational when `ndigits` is positive, otherwise returns an integer.
|
|
162
|
+
#
|
|
163
|
+
# Rational(3).ceil #=> 3
|
|
164
|
+
# Rational(2, 3).ceil #=> 1
|
|
165
|
+
# Rational(-3, 2).ceil #=> -1
|
|
166
|
+
#
|
|
167
|
+
# # decimal - 1 2 3 . 4 5 6
|
|
168
|
+
# # ^ ^ ^ ^ ^ ^
|
|
169
|
+
# # precision -3 -2 -1 0 +1 +2
|
|
170
|
+
#
|
|
171
|
+
# Rational('-123.456').ceil(+1).to_f #=> -123.4
|
|
172
|
+
# Rational('-123.456').ceil(-1) #=> -120
|
|
173
|
+
#
|
|
174
|
+
def ceil: () -> Integer
|
|
175
|
+
| (Integer digits) -> (Integer | Rational)
|
|
176
|
+
|
|
177
|
+
def clone: (?freeze: bool) -> self
|
|
178
|
+
|
|
179
|
+
def coerce: (Numeric) -> [Numeric, Numeric]
|
|
180
|
+
|
|
181
|
+
def conj: () -> Rational
|
|
182
|
+
|
|
183
|
+
def conjugate: () -> Rational
|
|
184
|
+
|
|
185
|
+
# Returns the denominator (always positive).
|
|
186
|
+
#
|
|
187
|
+
# Rational(7).denominator #=> 1
|
|
188
|
+
# Rational(7, 1).denominator #=> 1
|
|
189
|
+
# Rational(9, -4).denominator #=> 4
|
|
190
|
+
# Rational(-2, -10).denominator #=> 5
|
|
191
|
+
#
|
|
192
|
+
def denominator: () -> Integer
|
|
193
|
+
|
|
194
|
+
def div: (Numeric) -> Integer
|
|
195
|
+
|
|
196
|
+
def divmod: (Numeric) -> [Numeric, Numeric]
|
|
197
|
+
|
|
198
|
+
def dup: () -> self
|
|
199
|
+
|
|
200
|
+
def eql?: (untyped) -> bool
|
|
201
|
+
|
|
202
|
+
# Performs division and returns the value as a Float.
|
|
203
|
+
#
|
|
204
|
+
# Rational(2, 3).fdiv(1) #=> 0.6666666666666666
|
|
205
|
+
# Rational(2, 3).fdiv(0.5) #=> 1.3333333333333333
|
|
206
|
+
# Rational(2).fdiv(3) #=> 0.6666666666666666
|
|
207
|
+
#
|
|
208
|
+
def fdiv: (Numeric) -> Float
|
|
209
|
+
|
|
210
|
+
def finite?: () -> bool
|
|
211
|
+
|
|
212
|
+
# Returns the largest number less than or equal to `rat` with a precision of
|
|
213
|
+
# `ndigits` decimal digits (default: 0).
|
|
214
|
+
#
|
|
215
|
+
# When the precision is negative, the returned value is an integer with at least
|
|
216
|
+
# `ndigits.abs` trailing zeros.
|
|
217
|
+
#
|
|
218
|
+
# Returns a rational when `ndigits` is positive, otherwise returns an integer.
|
|
219
|
+
#
|
|
220
|
+
# Rational(3).floor #=> 3
|
|
221
|
+
# Rational(2, 3).floor #=> 0
|
|
222
|
+
# Rational(-3, 2).floor #=> -2
|
|
223
|
+
#
|
|
224
|
+
# # decimal - 1 2 3 . 4 5 6
|
|
225
|
+
# # ^ ^ ^ ^ ^ ^
|
|
226
|
+
# # precision -3 -2 -1 0 +1 +2
|
|
227
|
+
#
|
|
228
|
+
# Rational('-123.456').floor(+1).to_f #=> -123.5
|
|
229
|
+
# Rational('-123.456').floor(-1) #=> -130
|
|
230
|
+
#
|
|
231
|
+
def floor: () -> Integer
|
|
232
|
+
| (Integer digits) -> (Integer | Rational)
|
|
233
|
+
|
|
234
|
+
def hash: () -> Integer
|
|
235
|
+
|
|
236
|
+
def i: () -> Complex
|
|
237
|
+
|
|
238
|
+
def imag: () -> Integer
|
|
239
|
+
|
|
240
|
+
def imaginary: () -> Integer
|
|
241
|
+
|
|
242
|
+
def infinite?: () -> Integer?
|
|
243
|
+
|
|
244
|
+
# Returns the value as a string for inspection.
|
|
245
|
+
#
|
|
246
|
+
# Rational(2).inspect #=> "(2/1)"
|
|
247
|
+
# Rational(-8, 6).inspect #=> "(-4/3)"
|
|
248
|
+
# Rational('1/2').inspect #=> "(1/2)"
|
|
249
|
+
#
|
|
250
|
+
def inspect: () -> String
|
|
251
|
+
|
|
252
|
+
def integer?: () -> bool
|
|
253
|
+
|
|
254
|
+
# Returns the absolute value of `rat`.
|
|
255
|
+
#
|
|
256
|
+
# (1/2r).abs #=> (1/2)
|
|
257
|
+
# (-1/2r).abs #=> (1/2)
|
|
258
|
+
#
|
|
259
|
+
# Rational#magnitude is an alias for Rational#abs.
|
|
260
|
+
#
|
|
261
|
+
alias magnitude abs
|
|
262
|
+
|
|
263
|
+
def modulo: (Float) -> Float
|
|
264
|
+
| (Numeric) -> Rational
|
|
265
|
+
|
|
266
|
+
# Returns `true` if `rat` is less than 0.
|
|
267
|
+
#
|
|
268
|
+
def negative?: () -> bool
|
|
269
|
+
|
|
270
|
+
def nonzero?: () -> self?
|
|
271
|
+
|
|
272
|
+
# Returns the numerator.
|
|
273
|
+
#
|
|
274
|
+
# Rational(7).numerator #=> 7
|
|
275
|
+
# Rational(7, 1).numerator #=> 7
|
|
276
|
+
# Rational(9, -4).numerator #=> -9
|
|
277
|
+
# Rational(-2, -10).numerator #=> 1
|
|
278
|
+
#
|
|
279
|
+
def numerator: () -> Integer
|
|
280
|
+
|
|
281
|
+
alias phase angle
|
|
282
|
+
|
|
283
|
+
def polar: () -> [ Rational, Integer | Float ]
|
|
284
|
+
|
|
285
|
+
# Returns `true` if `rat` is greater than 0.
|
|
286
|
+
#
|
|
287
|
+
def positive?: () -> bool
|
|
288
|
+
|
|
289
|
+
# Performs division.
|
|
290
|
+
#
|
|
291
|
+
# Rational(2, 3) / Rational(2, 3) #=> (1/1)
|
|
292
|
+
# Rational(900) / Rational(1) #=> (900/1)
|
|
293
|
+
# Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
|
|
294
|
+
# Rational(9, 8) / 4 #=> (9/32)
|
|
295
|
+
# Rational(20, 9) / 9.8 #=> 0.22675736961451246
|
|
296
|
+
#
|
|
297
|
+
def quo: (Float) -> Float
|
|
298
|
+
| (Complex) -> Complex
|
|
299
|
+
| (Numeric) -> Rational
|
|
300
|
+
|
|
301
|
+
# Returns a simpler approximation of the value if the optional argument `eps` is
|
|
302
|
+
# given (rat-|eps| <= result <= rat+|eps|), self otherwise.
|
|
303
|
+
#
|
|
304
|
+
# r = Rational(5033165, 16777216)
|
|
305
|
+
# r.rationalize #=> (5033165/16777216)
|
|
306
|
+
# r.rationalize(Rational('0.01')) #=> (3/10)
|
|
307
|
+
# r.rationalize(Rational('0.1')) #=> (1/3)
|
|
308
|
+
#
|
|
309
|
+
def rationalize: (?Numeric eps) -> Rational
|
|
310
|
+
|
|
311
|
+
def real: () -> Rational
|
|
312
|
+
|
|
313
|
+
def real?: () -> true
|
|
314
|
+
|
|
315
|
+
def rect: () -> [ Rational, Numeric ]
|
|
316
|
+
|
|
317
|
+
alias rectangular rect
|
|
318
|
+
|
|
319
|
+
def remainder: (Float) -> Float
|
|
320
|
+
| (Numeric) -> Rational
|
|
321
|
+
|
|
322
|
+
# Returns `rat` rounded to the nearest value with a precision of `ndigits`
|
|
323
|
+
# decimal digits (default: 0).
|
|
324
|
+
#
|
|
325
|
+
# When the precision is negative, the returned value is an integer with at least
|
|
326
|
+
# `ndigits.abs` trailing zeros.
|
|
327
|
+
#
|
|
328
|
+
# Returns a rational when `ndigits` is positive, otherwise returns an integer.
|
|
329
|
+
#
|
|
330
|
+
# Rational(3).round #=> 3
|
|
331
|
+
# Rational(2, 3).round #=> 1
|
|
332
|
+
# Rational(-3, 2).round #=> -2
|
|
333
|
+
#
|
|
334
|
+
# # decimal - 1 2 3 . 4 5 6
|
|
335
|
+
# # ^ ^ ^ ^ ^ ^
|
|
336
|
+
# # precision -3 -2 -1 0 +1 +2
|
|
337
|
+
#
|
|
338
|
+
# Rational('-123.456').round(+1).to_f #=> -123.5
|
|
339
|
+
# Rational('-123.456').round(-1) #=> -120
|
|
340
|
+
#
|
|
341
|
+
# The optional `half` keyword argument is available similar to Float#round.
|
|
342
|
+
#
|
|
343
|
+
# Rational(25, 100).round(1, half: :up) #=> (3/10)
|
|
344
|
+
# Rational(25, 100).round(1, half: :down) #=> (1/5)
|
|
345
|
+
# Rational(25, 100).round(1, half: :even) #=> (1/5)
|
|
346
|
+
# Rational(35, 100).round(1, half: :up) #=> (2/5)
|
|
347
|
+
# Rational(35, 100).round(1, half: :down) #=> (3/10)
|
|
348
|
+
# Rational(35, 100).round(1, half: :even) #=> (2/5)
|
|
349
|
+
# Rational(-25, 100).round(1, half: :up) #=> (-3/10)
|
|
350
|
+
# Rational(-25, 100).round(1, half: :down) #=> (-1/5)
|
|
351
|
+
# Rational(-25, 100).round(1, half: :even) #=> (-1/5)
|
|
352
|
+
#
|
|
353
|
+
def round: (?half: :up | :down | :even) -> Integer
|
|
354
|
+
| (Integer digits, ?half: :up | :down | :even) -> (Integer | Rational)
|
|
355
|
+
|
|
356
|
+
def step: (?Numeric limit, ?Numeric step) { (Rational) -> void } -> self
|
|
357
|
+
| (?Numeric limit, ?Numeric step) -> Enumerator[Rational, self]
|
|
358
|
+
| (?by: Numeric, ?to: Numeric) { (Rational) -> void } -> self
|
|
359
|
+
| (?by: Numeric, ?to: Numeric) -> Enumerator[Rational, self]
|
|
360
|
+
|
|
361
|
+
def to_c: () -> Complex
|
|
362
|
+
|
|
363
|
+
# Returns the value as a Float.
|
|
364
|
+
#
|
|
365
|
+
# Rational(2).to_f #=> 2.0
|
|
366
|
+
# Rational(9, 4).to_f #=> 2.25
|
|
367
|
+
# Rational(-3, 4).to_f #=> -0.75
|
|
368
|
+
# Rational(20, 3).to_f #=> 6.666666666666667
|
|
369
|
+
#
|
|
370
|
+
def to_f: () -> Float
|
|
371
|
+
|
|
372
|
+
# Returns the truncated value as an integer.
|
|
373
|
+
#
|
|
374
|
+
# Equivalent to Rational#truncate.
|
|
375
|
+
#
|
|
376
|
+
# Rational(2, 3).to_i #=> 0
|
|
377
|
+
# Rational(3).to_i #=> 3
|
|
378
|
+
# Rational(300.6).to_i #=> 300
|
|
379
|
+
# Rational(98, 71).to_i #=> 1
|
|
380
|
+
# Rational(-31, 2).to_i #=> -15
|
|
381
|
+
#
|
|
382
|
+
def to_i: () -> Integer
|
|
383
|
+
|
|
384
|
+
alias to_int to_i
|
|
385
|
+
|
|
386
|
+
# Returns self.
|
|
387
|
+
#
|
|
388
|
+
# Rational(2).to_r #=> (2/1)
|
|
389
|
+
# Rational(-8, 6).to_r #=> (-4/3)
|
|
390
|
+
#
|
|
391
|
+
def to_r: () -> Rational
|
|
392
|
+
|
|
393
|
+
# Returns the value as a string.
|
|
394
|
+
#
|
|
395
|
+
# Rational(2).to_s #=> "2/1"
|
|
396
|
+
# Rational(-8, 6).to_s #=> "-4/3"
|
|
397
|
+
# Rational('1/2').to_s #=> "1/2"
|
|
398
|
+
#
|
|
399
|
+
def to_s: () -> String
|
|
400
|
+
|
|
401
|
+
# Returns `rat` truncated (toward zero) to a precision of `ndigits` decimal
|
|
402
|
+
# digits (default: 0).
|
|
403
|
+
#
|
|
404
|
+
# When the precision is negative, the returned value is an integer with at least
|
|
405
|
+
# `ndigits.abs` trailing zeros.
|
|
406
|
+
#
|
|
407
|
+
# Returns a rational when `ndigits` is positive, otherwise returns an integer.
|
|
408
|
+
#
|
|
409
|
+
# Rational(3).truncate #=> 3
|
|
410
|
+
# Rational(2, 3).truncate #=> 0
|
|
411
|
+
# Rational(-3, 2).truncate #=> -1
|
|
412
|
+
#
|
|
413
|
+
# # decimal - 1 2 3 . 4 5 6
|
|
414
|
+
# # ^ ^ ^ ^ ^ ^
|
|
415
|
+
# # precision -3 -2 -1 0 +1 +2
|
|
416
|
+
#
|
|
417
|
+
# Rational('-123.456').truncate(+1).to_f #=> -123.4
|
|
418
|
+
# Rational('-123.456').truncate(-1) #=> -120
|
|
419
|
+
#
|
|
420
|
+
def truncate: () -> Integer
|
|
421
|
+
| (Integer ndigits) -> (Integer | Rational)
|
|
422
|
+
|
|
423
|
+
def zero?: () -> bool
|
|
424
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# The module storing Ruby interpreter configurations on building.
|
|
2
|
+
#
|
|
3
|
+
# This file was created by mkconfig.rb when ruby was built. It contains build
|
|
4
|
+
# information for ruby which is used e.g. by mkmf to build compatible native
|
|
5
|
+
# extensions. Any changes made to this file will be lost the next time ruby is
|
|
6
|
+
# built.
|
|
7
|
+
#
|
|
8
|
+
module RbConfig
|
|
9
|
+
# expands variable with given `val` value.
|
|
10
|
+
#
|
|
11
|
+
# RbConfig.expand("$(bindir)") # => /home/foobar/all-ruby/ruby19x/bin
|
|
12
|
+
#
|
|
13
|
+
def self.expand: (String val, ?Hash[String, String] config) -> String
|
|
14
|
+
|
|
15
|
+
def self.fire_update!: (String key, String val, ?Hash[String, String] mkconf, ?Hash[String, String] conf) -> Array[String]?
|
|
16
|
+
|
|
17
|
+
def self.ruby: () -> String
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# The hash configurations stored.
|
|
21
|
+
#
|
|
22
|
+
RbConfig::CONFIG: Hash[String, String]
|
|
23
|
+
|
|
24
|
+
# DESTDIR on make install.
|
|
25
|
+
#
|
|
26
|
+
RbConfig::DESTDIR: String
|
|
27
|
+
|
|
28
|
+
# Almost same with CONFIG. MAKEFILE_CONFIG has other variable reference like
|
|
29
|
+
# below.
|
|
30
|
+
#
|
|
31
|
+
# MAKEFILE_CONFIG["bindir"] = "$(exec_prefix)/bin"
|
|
32
|
+
#
|
|
33
|
+
# The values of this constant is used for creating Makefile.
|
|
34
|
+
#
|
|
35
|
+
# require 'rbconfig'
|
|
36
|
+
#
|
|
37
|
+
# print <<-END_OF_MAKEFILE
|
|
38
|
+
# prefix = #{Config::MAKEFILE_CONFIG['prefix']}
|
|
39
|
+
# exec_prefix = #{Config::MAKEFILE_CONFIG['exec_prefix']}
|
|
40
|
+
# bindir = #{Config::MAKEFILE_CONFIG['bindir']}
|
|
41
|
+
# END_OF_MAKEFILE
|
|
42
|
+
#
|
|
43
|
+
# => prefix = /usr/local
|
|
44
|
+
# exec_prefix = $(prefix)
|
|
45
|
+
# bindir = $(exec_prefix)/bin MAKEFILE_CONFIG = {}
|
|
46
|
+
#
|
|
47
|
+
# RbConfig.expand is used for resolving references like above in rbconfig.
|
|
48
|
+
#
|
|
49
|
+
# require 'rbconfig'
|
|
50
|
+
# p Config.expand(Config::MAKEFILE_CONFIG["bindir"])
|
|
51
|
+
# # => "/usr/local/bin"
|
|
52
|
+
#
|
|
53
|
+
RbConfig::MAKEFILE_CONFIG: Hash[String, String]
|
|
54
|
+
|
|
55
|
+
# Ruby installed directory.
|
|
56
|
+
#
|
|
57
|
+
RbConfig::TOPDIR: String
|