rbs 0.10.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +9 -9
- data/CHANGELOG.md +29 -0
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/Rakefile +16 -6
- data/Steepfile +28 -0
- data/bin/steep +4 -0
- data/bin/test_runner.rb +7 -5
- data/docs/syntax.md +14 -1
- data/lib/rbs/ast/comment.rb +7 -1
- data/lib/rbs/ast/declarations.rb +15 -9
- data/lib/rbs/ast/members.rb +3 -8
- data/lib/rbs/buffer.rb +1 -1
- data/lib/rbs/cli.rb +72 -3
- data/lib/rbs/constant.rb +1 -1
- data/lib/rbs/constant_table.rb +9 -8
- data/lib/rbs/definition.rb +31 -14
- data/lib/rbs/definition_builder.rb +97 -67
- data/lib/rbs/environment.rb +28 -11
- data/lib/rbs/environment_loader.rb +67 -47
- data/lib/rbs/location.rb +1 -5
- data/lib/rbs/method_type.rb +5 -5
- data/lib/rbs/namespace.rb +14 -3
- data/lib/rbs/parser.y +2 -12
- data/lib/rbs/prototype/rb.rb +3 -5
- data/lib/rbs/prototype/rbi.rb +1 -4
- data/lib/rbs/prototype/runtime.rb +0 -4
- data/lib/rbs/substitution.rb +4 -3
- data/lib/rbs/test/setup.rb +5 -1
- data/lib/rbs/test/setup_helper.rb +15 -0
- data/lib/rbs/test/tester.rb +7 -5
- data/lib/rbs/test/type_check.rb +14 -2
- data/lib/rbs/type_name.rb +18 -1
- data/lib/rbs/type_name_resolver.rb +10 -3
- data/lib/rbs/types.rb +27 -21
- data/lib/rbs/variance_calculator.rb +9 -6
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +26 -17
- data/sig/annotation.rbs +26 -0
- data/sig/buffer.rbs +28 -0
- data/sig/builtin_names.rbs +41 -0
- data/sig/comment.rbs +26 -0
- data/sig/constant.rbs +21 -0
- data/sig/constant_table.rbs +30 -0
- data/sig/declarations.rbs +202 -0
- data/sig/definition.rbs +129 -0
- data/sig/definition_builder.rbs +94 -0
- data/sig/environment.rbs +94 -0
- data/sig/environment_loader.rbs +58 -0
- data/sig/location.rbs +52 -0
- data/sig/members.rbs +160 -0
- data/sig/method_types.rbs +40 -0
- data/sig/namespace.rbs +124 -0
- data/sig/polyfill.rbs +3 -0
- data/sig/rbs.rbs +3 -0
- data/sig/substitution.rbs +39 -0
- data/sig/type_name_resolver.rbs +24 -0
- data/sig/typename.rbs +70 -0
- data/sig/types.rbs +361 -0
- data/sig/util.rbs +13 -0
- data/sig/variance_calculator.rbs +35 -0
- data/sig/version.rbs +3 -0
- data/sig/writer.rbs +40 -0
- data/stdlib/bigdecimal/big_decimal.rbs +887 -0
- data/stdlib/bigdecimal/math/big_math.rbs +142 -0
- data/stdlib/builtin/array.rbs +2 -1
- data/stdlib/builtin/builtin.rbs +0 -3
- data/stdlib/builtin/hash.rbs +1 -1
- data/stdlib/builtin/kernel.rbs +2 -0
- data/stdlib/builtin/math.rbs +26 -26
- data/stdlib/builtin/struct.rbs +9 -10
- data/stdlib/date/date.rbs +1056 -0
- data/stdlib/date/date_time.rbs +582 -0
- data/stdlib/forwardable/forwardable.rbs +204 -0
- data/stdlib/pathname/pathname.rbs +2 -0
- data/stdlib/pty/pty.rbs +5 -29
- data/stdlib/set/set.rbs +1 -1
- data/stdlib/uri/file.rbs +167 -0
- data/stdlib/uri/generic.rbs +875 -0
- data/stdlib/uri/http.rbs +158 -0
- data/stdlib/uri/https.rbs +108 -0
- data/stdlib/uri/ldap.rbs +224 -0
- data/stdlib/uri/ldaps.rbs +108 -0
- data/stdlib/zlib/zlib.rbs +1 -1
- data/steep/Gemfile +3 -0
- data/steep/Gemfile.lock +51 -0
- metadata +45 -5
@@ -0,0 +1,142 @@
|
|
1
|
+
# Provides mathematical functions.
|
2
|
+
#
|
3
|
+
# Example:
|
4
|
+
#
|
5
|
+
# require "bigdecimal/math"
|
6
|
+
#
|
7
|
+
# include BigMath
|
8
|
+
#
|
9
|
+
# a = BigDecimal((PI(100)/2).to_s)
|
10
|
+
# puts sin(a,100) # => 0.99999999999999999999......e0
|
11
|
+
#
|
12
|
+
module BigMath
|
13
|
+
# Computes e (the base of natural logarithms) to the specified number of digits
|
14
|
+
# of precision, `numeric`.
|
15
|
+
#
|
16
|
+
# BigMath.E(10).to_s
|
17
|
+
# #=> "0.271828182845904523536028752390026306410273e1"
|
18
|
+
#
|
19
|
+
def self.E: (Numeric prec) -> BigDecimal
|
20
|
+
|
21
|
+
# Computes the value of pi to the specified number of digits of precision,
|
22
|
+
# `numeric`.
|
23
|
+
#
|
24
|
+
# BigMath.PI(10).to_s
|
25
|
+
# #=> "0.3141592653589793238462643388813853786957412e1"
|
26
|
+
#
|
27
|
+
def self.PI: (Numeric prec) -> BigDecimal
|
28
|
+
|
29
|
+
# Computes the arctangent of `decimal` to the specified number of digits of
|
30
|
+
# precision, `numeric`.
|
31
|
+
#
|
32
|
+
# If `decimal` is NaN, returns NaN.
|
33
|
+
#
|
34
|
+
# BigMath.atan(BigDecimal('-1'), 16).to_s
|
35
|
+
# #=> "-0.785398163397448309615660845819878471907514682065e0"
|
36
|
+
#
|
37
|
+
def self.atan: (BigDecimal x, Numeric prec) -> BigDecimal
|
38
|
+
|
39
|
+
# Computes the cosine of `decimal` to the specified number of digits of
|
40
|
+
# precision, `numeric`.
|
41
|
+
#
|
42
|
+
# If `decimal` is Infinity or NaN, returns NaN.
|
43
|
+
#
|
44
|
+
# BigMath.cos(BigMath.PI(4), 16).to_s
|
45
|
+
# #=> "-0.999999999999999999999999999999856613163740061349e0"
|
46
|
+
#
|
47
|
+
def self.cos: (BigDecimal x, Numeric prec) -> BigDecimal
|
48
|
+
|
49
|
+
# Computes the value of e (the base of natural logarithms) raised to the power
|
50
|
+
# of `decimal`, to the specified number of digits of precision.
|
51
|
+
#
|
52
|
+
# If `decimal` is infinity, returns Infinity.
|
53
|
+
#
|
54
|
+
# If `decimal` is NaN, returns NaN.
|
55
|
+
#
|
56
|
+
def self.exp: (BigDecimal, Numeric prec) -> BigDecimal
|
57
|
+
|
58
|
+
# Computes the natural logarithm of `decimal` to the specified number of digits
|
59
|
+
# of precision, `numeric`.
|
60
|
+
#
|
61
|
+
# If `decimal` is zero or negative, raises Math::DomainError.
|
62
|
+
#
|
63
|
+
# If `decimal` is positive infinity, returns Infinity.
|
64
|
+
#
|
65
|
+
# If `decimal` is NaN, returns NaN.
|
66
|
+
#
|
67
|
+
def self.log: (BigDecimal, Numeric prec) -> BigDecimal
|
68
|
+
|
69
|
+
# Computes the sine of `decimal` to the specified number of digits of precision,
|
70
|
+
# `numeric`.
|
71
|
+
#
|
72
|
+
# If `decimal` is Infinity or NaN, returns NaN.
|
73
|
+
#
|
74
|
+
# BigMath.sin(BigMath.PI(5)/4, 5).to_s
|
75
|
+
# #=> "0.70710678118654752440082036563292800375e0"
|
76
|
+
#
|
77
|
+
def self.sin: (BigDecimal x, Numeric prec) -> BigDecimal
|
78
|
+
|
79
|
+
# Computes the square root of `decimal` to the specified number of digits of
|
80
|
+
# precision, `numeric`.
|
81
|
+
#
|
82
|
+
# BigMath.sqrt(BigDecimal('2'), 16).to_s
|
83
|
+
# #=> "0.1414213562373095048801688724e1"
|
84
|
+
#
|
85
|
+
def self.sqrt: (BigDecimal x, Numeric prec) -> BigDecimal
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
# Computes e (the base of natural logarithms) to the specified number of digits
|
90
|
+
# of precision, `numeric`.
|
91
|
+
#
|
92
|
+
# BigMath.E(10).to_s
|
93
|
+
# #=> "0.271828182845904523536028752390026306410273e1"
|
94
|
+
#
|
95
|
+
def E: (Numeric prec) -> BigDecimal
|
96
|
+
|
97
|
+
# Computes the value of pi to the specified number of digits of precision,
|
98
|
+
# `numeric`.
|
99
|
+
#
|
100
|
+
# BigMath.PI(10).to_s
|
101
|
+
# #=> "0.3141592653589793238462643388813853786957412e1"
|
102
|
+
#
|
103
|
+
def PI: (Numeric prec) -> BigDecimal
|
104
|
+
|
105
|
+
# Computes the arctangent of `decimal` to the specified number of digits of
|
106
|
+
# precision, `numeric`.
|
107
|
+
#
|
108
|
+
# If `decimal` is NaN, returns NaN.
|
109
|
+
#
|
110
|
+
# BigMath.atan(BigDecimal('-1'), 16).to_s
|
111
|
+
# #=> "-0.785398163397448309615660845819878471907514682065e0"
|
112
|
+
#
|
113
|
+
def atan: (BigDecimal x, Numeric prec) -> BigDecimal
|
114
|
+
|
115
|
+
# Computes the cosine of `decimal` to the specified number of digits of
|
116
|
+
# precision, `numeric`.
|
117
|
+
#
|
118
|
+
# If `decimal` is Infinity or NaN, returns NaN.
|
119
|
+
#
|
120
|
+
# BigMath.cos(BigMath.PI(4), 16).to_s
|
121
|
+
# #=> "-0.999999999999999999999999999999856613163740061349e0"
|
122
|
+
#
|
123
|
+
def cos: (BigDecimal x, Numeric prec) -> BigDecimal
|
124
|
+
|
125
|
+
# Computes the sine of `decimal` to the specified number of digits of precision,
|
126
|
+
# `numeric`.
|
127
|
+
#
|
128
|
+
# If `decimal` is Infinity or NaN, returns NaN.
|
129
|
+
#
|
130
|
+
# BigMath.sin(BigMath.PI(5)/4, 5).to_s
|
131
|
+
# #=> "0.70710678118654752440082036563292800375e0"
|
132
|
+
#
|
133
|
+
def sin: (BigDecimal x, Numeric prec) -> BigDecimal
|
134
|
+
|
135
|
+
# Computes the square root of `decimal` to the specified number of digits of
|
136
|
+
# precision, `numeric`.
|
137
|
+
#
|
138
|
+
# BigMath.sqrt(BigDecimal('2'), 16).to_s
|
139
|
+
# #=> "0.1414213562373095048801688724e1"
|
140
|
+
#
|
141
|
+
def sqrt: (BigDecimal x, Numeric prec) -> BigDecimal
|
142
|
+
end
|
data/stdlib/builtin/array.rbs
CHANGED
@@ -626,7 +626,8 @@ class Array[unchecked out Elem] < Object
|
|
626
626
|
# a.collect!.with_index {|x, i| x[0...i] }
|
627
627
|
# a #=> ["", "b", "c!", "d!"]
|
628
628
|
#
|
629
|
-
|
629
|
+
# collect! is monomorphic because of RBS limitation.
|
630
|
+
def collect!: () { (Elem item) -> Elem } -> self
|
630
631
|
| () -> ::Enumerator[Elem, self]
|
631
632
|
|
632
633
|
# When invoked with a block, yields all combinations of length `n` of elements
|
data/stdlib/builtin/builtin.rbs
CHANGED
data/stdlib/builtin/hash.rbs
CHANGED
@@ -1016,7 +1016,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
1016
1016
|
# h["d"] #=> "Go Fish: d"
|
1017
1017
|
# h.keys #=> ["c", "d"]
|
1018
1018
|
#
|
1019
|
-
|
1019
|
+
def initialize: () -> void
|
1020
1020
|
| (untyped default) -> void
|
1021
1021
|
| [A, B] () { (Hash[A, B] hash, A key) -> B } -> void
|
1022
1022
|
|
data/stdlib/builtin/kernel.rbs
CHANGED
data/stdlib/builtin/math.rbs
CHANGED
@@ -13,7 +13,7 @@ module Math
|
|
13
13
|
#
|
14
14
|
# Math.acos(0) == Math::PI/2 #=> true
|
15
15
|
#
|
16
|
-
def self.acos: (
|
16
|
+
def self.acos: (Numeric x) -> Float
|
17
17
|
|
18
18
|
# Computes the inverse hyperbolic cosine of `x`.
|
19
19
|
#
|
@@ -23,7 +23,7 @@ module Math
|
|
23
23
|
#
|
24
24
|
# Math.acosh(1) #=> 0.0
|
25
25
|
#
|
26
|
-
def self.acosh: (
|
26
|
+
def self.acosh: (Numeric x) -> Float
|
27
27
|
|
28
28
|
# Computes the arc sine of `x`. Returns -PI/2..PI/2.
|
29
29
|
#
|
@@ -33,7 +33,7 @@ module Math
|
|
33
33
|
#
|
34
34
|
# Math.asin(1) == Math::PI/2 #=> true
|
35
35
|
#
|
36
|
-
def self.asin: (
|
36
|
+
def self.asin: (Numeric x) -> Float
|
37
37
|
|
38
38
|
# Computes the inverse hyperbolic sine of `x`.
|
39
39
|
#
|
@@ -43,7 +43,7 @@ module Math
|
|
43
43
|
#
|
44
44
|
# Math.asinh(1) #=> 0.881373587019543
|
45
45
|
#
|
46
|
-
def self.asinh: (
|
46
|
+
def self.asinh: (Numeric x) -> Float
|
47
47
|
|
48
48
|
# Computes the arc tangent of `x`. Returns -PI/2..PI/2.
|
49
49
|
#
|
@@ -53,7 +53,7 @@ module Math
|
|
53
53
|
#
|
54
54
|
# Math.atan(0) #=> 0.0
|
55
55
|
#
|
56
|
-
def self.atan: (
|
56
|
+
def self.atan: (Numeric x) -> Float
|
57
57
|
|
58
58
|
# Computes the arc tangent given `y` and `x`. Returns a Float in the range
|
59
59
|
# -PI..PI. Return value is a angle in radians between the positive x-axis of
|
@@ -78,7 +78,7 @@ module Math
|
|
78
78
|
# Math.atan2(-INFINITY, INFINITY) #=> -0.7853981633974483
|
79
79
|
# Math.atan2(-INFINITY, -INFINITY) #=> -2.356194490192345
|
80
80
|
#
|
81
|
-
def self.atan2: (
|
81
|
+
def self.atan2: (Numeric y, Numeric x) -> Float
|
82
82
|
|
83
83
|
# Computes the inverse hyperbolic tangent of `x`.
|
84
84
|
#
|
@@ -88,7 +88,7 @@ module Math
|
|
88
88
|
#
|
89
89
|
# Math.atanh(1) #=> Infinity
|
90
90
|
#
|
91
|
-
def self.atanh: (
|
91
|
+
def self.atanh: (Numeric x) -> Float
|
92
92
|
|
93
93
|
# Returns the cube root of `x`.
|
94
94
|
#
|
@@ -119,7 +119,7 @@ module Math
|
|
119
119
|
# # [8, 2.0, 8.0]
|
120
120
|
# # [9, 2.0800838230519, 9.0]
|
121
121
|
#
|
122
|
-
def self.cbrt: (
|
122
|
+
def self.cbrt: (Numeric x) -> Float
|
123
123
|
|
124
124
|
# Computes the cosine of `x` (expressed in radians). Returns a Float in the
|
125
125
|
# range -1.0..1.0.
|
@@ -130,7 +130,7 @@ module Math
|
|
130
130
|
#
|
131
131
|
# Math.cos(Math::PI) #=> -1.0
|
132
132
|
#
|
133
|
-
def self.cos: (
|
133
|
+
def self.cos: (Numeric x) -> Float
|
134
134
|
|
135
135
|
# Computes the hyperbolic cosine of `x` (expressed in radians).
|
136
136
|
#
|
@@ -140,7 +140,7 @@ module Math
|
|
140
140
|
#
|
141
141
|
# Math.cosh(0) #=> 1.0
|
142
142
|
#
|
143
|
-
def self.cosh: (
|
143
|
+
def self.cosh: (Numeric x) -> Float
|
144
144
|
|
145
145
|
# Calculates the error function of `x`.
|
146
146
|
#
|
@@ -150,7 +150,7 @@ module Math
|
|
150
150
|
#
|
151
151
|
# Math.erf(0) #=> 0.0
|
152
152
|
#
|
153
|
-
def self.erf: (
|
153
|
+
def self.erf: (Numeric x) -> Float
|
154
154
|
|
155
155
|
# Calculates the complementary error function of x.
|
156
156
|
#
|
@@ -160,7 +160,7 @@ module Math
|
|
160
160
|
#
|
161
161
|
# Math.erfc(0) #=> 1.0
|
162
162
|
#
|
163
|
-
def self.erfc: (
|
163
|
+
def self.erfc: (Numeric x) -> Float
|
164
164
|
|
165
165
|
# Returns e**x.
|
166
166
|
#
|
@@ -172,7 +172,7 @@ module Math
|
|
172
172
|
# Math.exp(1) #=> 2.718281828459045
|
173
173
|
# Math.exp(1.5) #=> 4.4816890703380645
|
174
174
|
#
|
175
|
-
def self.exp: (
|
175
|
+
def self.exp: (Numeric x) -> Float
|
176
176
|
|
177
177
|
# Returns a two-element array containing the normalized fraction (a Float) and
|
178
178
|
# exponent (an Integer) of `x`.
|
@@ -180,7 +180,7 @@ module Math
|
|
180
180
|
# fraction, exponent = Math.frexp(1234) #=> [0.6025390625, 11]
|
181
181
|
# fraction * 2**exponent #=> 1234.0
|
182
182
|
#
|
183
|
-
def self.frexp: (
|
183
|
+
def self.frexp: (Numeric x) -> [ Float, Integer ]
|
184
184
|
|
185
185
|
# Calculates the gamma function of x.
|
186
186
|
#
|
@@ -216,21 +216,21 @@ module Math
|
|
216
216
|
# # [25, 6.204484017332391e+23, 620448401733239439360000]
|
217
217
|
# # [26, 1.5511210043330954e+25, 15511210043330985984000000]
|
218
218
|
#
|
219
|
-
def self.gamma: (
|
219
|
+
def self.gamma: (Numeric x) -> Float
|
220
220
|
|
221
221
|
# Returns sqrt(x**2 + y**2), the hypotenuse of a right-angled triangle with
|
222
222
|
# sides `x` and `y`.
|
223
223
|
#
|
224
224
|
# Math.hypot(3, 4) #=> 5.0
|
225
225
|
#
|
226
|
-
def self.hypot: (
|
226
|
+
def self.hypot: (Numeric x, Numeric y) -> Float
|
227
227
|
|
228
228
|
# Returns the value of `fraction`*(2**`exponent`).
|
229
229
|
#
|
230
230
|
# fraction, exponent = Math.frexp(1234)
|
231
231
|
# Math.ldexp(fraction, exponent) #=> 1234.0
|
232
232
|
#
|
233
|
-
def self.ldexp: (
|
233
|
+
def self.ldexp: (Numeric fraction, Numeric exponent) -> Float
|
234
234
|
|
235
235
|
# Calculates the logarithmic gamma of `x` and the sign of gamma of `x`.
|
236
236
|
#
|
@@ -241,9 +241,9 @@ module Math
|
|
241
241
|
#
|
242
242
|
# Math.lgamma(0) #=> [Infinity, 1]
|
243
243
|
#
|
244
|
-
def self.lgamma: (
|
244
|
+
def self.lgamma: (Numeric x) -> [ Float, Integer ]
|
245
245
|
|
246
|
-
def self.log: (
|
246
|
+
def self.log: (Numeric x, ?Numeric base) -> Float
|
247
247
|
|
248
248
|
# Returns the base 10 logarithm of `x`.
|
249
249
|
#
|
@@ -255,7 +255,7 @@ module Math
|
|
255
255
|
# Math.log10(10) #=> 1.0
|
256
256
|
# Math.log10(10**100) #=> 100.0
|
257
257
|
#
|
258
|
-
def self.log10: (
|
258
|
+
def self.log10: (Numeric x) -> Float
|
259
259
|
|
260
260
|
# Returns the base 2 logarithm of `x`.
|
261
261
|
#
|
@@ -268,7 +268,7 @@ module Math
|
|
268
268
|
# Math.log2(32768) #=> 15.0
|
269
269
|
# Math.log2(65536) #=> 16.0
|
270
270
|
#
|
271
|
-
def self.log2: (
|
271
|
+
def self.log2: (Numeric x) -> Float
|
272
272
|
|
273
273
|
# Computes the sine of `x` (expressed in radians). Returns a Float in the range
|
274
274
|
# -1.0..1.0.
|
@@ -279,7 +279,7 @@ module Math
|
|
279
279
|
#
|
280
280
|
# Math.sin(Math::PI/2) #=> 1.0
|
281
281
|
#
|
282
|
-
def self.sin: (
|
282
|
+
def self.sin: (Numeric x) -> Float
|
283
283
|
|
284
284
|
# Computes the hyperbolic sine of `x` (expressed in radians).
|
285
285
|
#
|
@@ -289,7 +289,7 @@ module Math
|
|
289
289
|
#
|
290
290
|
# Math.sinh(0) #=> 0.0
|
291
291
|
#
|
292
|
-
def self.sinh: (
|
292
|
+
def self.sinh: (Numeric x) -> Float
|
293
293
|
|
294
294
|
# Returns the non-negative square root of `x`.
|
295
295
|
#
|
@@ -319,7 +319,7 @@ module Math
|
|
319
319
|
#
|
320
320
|
# See also BigDecimal#sqrt and Integer.sqrt.
|
321
321
|
#
|
322
|
-
def self.sqrt: (
|
322
|
+
def self.sqrt: (Numeric x) -> Float
|
323
323
|
|
324
324
|
# Computes the tangent of `x` (expressed in radians).
|
325
325
|
#
|
@@ -329,7 +329,7 @@ module Math
|
|
329
329
|
#
|
330
330
|
# Math.tan(0) #=> 0.0
|
331
331
|
#
|
332
|
-
def self.tan: (
|
332
|
+
def self.tan: (Numeric x) -> Float
|
333
333
|
|
334
334
|
# Computes the hyperbolic tangent of `x` (expressed in radians).
|
335
335
|
#
|
@@ -339,7 +339,7 @@ module Math
|
|
339
339
|
#
|
340
340
|
# Math.tanh(0) #=> 0.0
|
341
341
|
#
|
342
|
-
def self.tanh: (
|
342
|
+
def self.tanh: (Numeric x) -> Float
|
343
343
|
end
|
344
344
|
|
345
345
|
# Definition of the mathematical constant E for Euler's number (e) as a Float
|
data/stdlib/builtin/struct.rbs
CHANGED
@@ -1,40 +1,39 @@
|
|
1
1
|
# A [Struct](Struct) is a convenient way to bundle a
|
2
2
|
# number of attributes together, using accessor methods, without having to
|
3
3
|
# write an explicit class.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# The [Struct](Struct) class generates new subclasses
|
6
6
|
# that hold a set of members and their values. For each member a reader
|
7
7
|
# and writer method is created similar to
|
8
8
|
# [Module\#attr\_accessor](https://ruby-doc.org/core-2.6.3/Module.html#method-i-attr_accessor)
|
9
9
|
# .
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# ```ruby
|
12
12
|
# Customer = Struct.new(:name, :address) do
|
13
13
|
# def greeting
|
14
14
|
# "Hello #{name}!"
|
15
15
|
# end
|
16
16
|
# end
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# dave = Customer.new("Dave", "123 Main")
|
19
19
|
# dave.name #=> "Dave"
|
20
20
|
# dave.greeting #=> "Hello Dave!"
|
21
21
|
# ```
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# See [::new](Struct#method-c-new) for further
|
24
24
|
# examples of creating struct subclasses and instances.
|
25
|
-
#
|
25
|
+
#
|
26
26
|
# In the method descriptions that follow, a "member" parameter refers to a
|
27
27
|
# struct member which is either a quoted string ( `"name"` ) or a
|
28
28
|
# [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html) ( `:name` ).
|
29
29
|
class Struct[Elem] < Object
|
30
30
|
include Enumerable[Elem, Struct[Elem]]
|
31
31
|
|
32
|
-
|
32
|
+
type attribute_name = Symbol | String
|
33
33
|
|
34
|
-
def
|
35
|
-
| () -> self
|
34
|
+
def initialize: (attribute_name, *attribute_name, ?keyword_init: bool) ?{ () -> void } -> void
|
36
35
|
|
37
|
-
def
|
36
|
+
def each: () { (Elem) -> untyped } -> untyped
|
38
37
|
|
39
|
-
def
|
38
|
+
def self.members: () -> ::Array[Symbol]
|
40
39
|
end
|