rbs 3.0.0.dev.2 → 3.0.0.dev.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +2 -2
  6. data/Steepfile +1 -1
  7. data/core/array.rbs +573 -423
  8. data/core/basic_object.rbs +11 -39
  9. data/core/binding.rbs +1 -1
  10. data/core/builtin.rbs +8 -0
  11. data/core/class.rbs +37 -0
  12. data/core/comparable.rbs +7 -18
  13. data/core/complex.rbs +2 -2
  14. data/core/data.rbs +419 -0
  15. data/core/dir.rbs +52 -104
  16. data/core/encoding.rbs +22 -181
  17. data/core/enumerable.rbs +212 -175
  18. data/core/enumerator/product.rbs +96 -0
  19. data/core/enumerator.rbs +57 -8
  20. data/core/errors.rbs +8 -2
  21. data/core/exception.rbs +41 -0
  22. data/core/fiber.rbs +95 -12
  23. data/core/file.rbs +840 -275
  24. data/core/file_test.rbs +34 -19
  25. data/core/float.rbs +40 -96
  26. data/core/gc.rbs +15 -3
  27. data/core/hash.rbs +113 -175
  28. data/core/integer.rbs +85 -145
  29. data/core/io/buffer.rbs +187 -60
  30. data/core/io/wait.rbs +28 -16
  31. data/core/io.rbs +1859 -1389
  32. data/core/kernel.rbs +525 -961
  33. data/core/match_data.rbs +306 -142
  34. data/core/math.rbs +506 -234
  35. data/core/method.rbs +0 -24
  36. data/core/module.rbs +110 -17
  37. data/core/nil_class.rbs +2 -0
  38. data/core/numeric.rbs +76 -144
  39. data/core/object.rbs +88 -212
  40. data/core/proc.rbs +17 -5
  41. data/core/process.rbs +22 -5
  42. data/core/ractor.rbs +1 -1
  43. data/core/random.rbs +20 -3
  44. data/core/range.rbs +91 -89
  45. data/core/rational.rbs +2 -3
  46. data/core/rbs/unnamed/argf.rbs +177 -120
  47. data/core/rbs/unnamed/env_class.rbs +89 -163
  48. data/core/rbs/unnamed/random.rbs +36 -12
  49. data/core/refinement.rbs +8 -0
  50. data/core/regexp.rbs +462 -272
  51. data/core/ruby_vm.rbs +210 -0
  52. data/{stdlib/set/0 → core}/set.rbs +43 -47
  53. data/core/string.rbs +1403 -1332
  54. data/core/string_io.rbs +191 -107
  55. data/core/struct.rbs +67 -63
  56. data/core/symbol.rbs +187 -201
  57. data/core/thread.rbs +40 -35
  58. data/core/time.rbs +902 -826
  59. data/core/trace_point.rbs +55 -6
  60. data/core/unbound_method.rbs +48 -24
  61. data/docs/collection.md +4 -0
  62. data/docs/syntax.md +55 -0
  63. data/ext/rbs_extension/parser.c +5 -6
  64. data/lib/rbs/cli.rb +6 -1
  65. data/lib/rbs/collection/cleaner.rb +8 -1
  66. data/lib/rbs/collection/config/lockfile.rb +3 -1
  67. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  68. data/lib/rbs/collection/config.rb +1 -1
  69. data/lib/rbs/collection/sources/git.rb +9 -2
  70. data/lib/rbs/collection/sources/local.rb +79 -0
  71. data/lib/rbs/collection/sources.rb +8 -1
  72. data/lib/rbs/environment.rb +6 -5
  73. data/lib/rbs/environment_loader.rb +3 -2
  74. data/lib/rbs/errors.rb +18 -0
  75. data/lib/rbs/locator.rb +26 -7
  76. data/lib/rbs/sorter.rb +2 -2
  77. data/lib/rbs/version.rb +1 -1
  78. data/sig/collection/sources.rbs +32 -3
  79. data/sig/environment.rbs +2 -3
  80. data/sig/locator.rbs +14 -2
  81. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  82. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  83. data/stdlib/cgi/0/core.rbs +16 -0
  84. data/stdlib/coverage/0/coverage.rbs +50 -8
  85. data/stdlib/csv/0/csv.rbs +1 -1
  86. data/stdlib/date/0/date.rbs +856 -726
  87. data/stdlib/date/0/date_time.rbs +83 -210
  88. data/stdlib/erb/0/erb.rbs +13 -36
  89. data/stdlib/etc/0/etc.rbs +127 -20
  90. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  91. data/stdlib/logger/0/logger.rbs +466 -316
  92. data/stdlib/net-http/0/net-http.rbs +2211 -534
  93. data/stdlib/nkf/0/nkf.rbs +5 -5
  94. data/stdlib/objspace/0/objspace.rbs +31 -14
  95. data/stdlib/openssl/0/openssl.rbs +11 -7
  96. data/stdlib/optparse/0/optparse.rbs +20 -17
  97. data/stdlib/pathname/0/pathname.rbs +21 -4
  98. data/stdlib/pstore/0/pstore.rbs +378 -154
  99. data/stdlib/pty/0/pty.rbs +24 -8
  100. data/stdlib/ripper/0/ripper.rbs +1650 -0
  101. data/stdlib/socket/0/addrinfo.rbs +9 -15
  102. data/stdlib/socket/0/socket.rbs +36 -3
  103. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  104. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  105. data/stdlib/time/0/time.rbs +2 -2
  106. data/stdlib/uri/0/file.rbs +5 -0
  107. data/stdlib/uri/0/generic.rbs +2 -2
  108. data/stdlib/yaml/0/yaml.rbs +2 -2
  109. data/stdlib/zlib/0/zlib.rbs +1 -1
  110. metadata +8 -6
  111. data/core/deprecated.rbs +0 -9
  112. data/sig/shims/ripper.rbs +0 -8
@@ -49,45 +49,17 @@
49
49
  #
50
50
  # These are the methods defined for BasicObject:
51
51
  #
52
- # ::new
53
- # : Returns a new BasicObject instance.
54
- #
55
- # [!](#method-i-21)
56
- # : Returns the boolean negation of `self`: `true` or `false`.
57
- #
58
- # [!=](#method-i-21-3D)
59
- # : Returns whether `self` and the given object are *not* equal.
60
- #
61
- # [==](#method-i-3D-3D)
62
- # : Returns whether `self` and the given object are equivalent.
63
- #
64
- # [__id__](#method-i-__id__)
65
- # : Returns the integer object identifier for `self`.
66
- #
67
- # [__send__](#method-i-__send__)
68
- # : Calls the method identified by the given symbol.
69
- #
70
- # #equal?
71
- # : Returns whether `self` and the given object are the same object.
72
- #
73
- # #instance_eval
74
- # : Evaluates the given string or block in the context of `self`.
75
- #
76
- # #instance_exec
77
- # : Executes the given block in the context of `self`, passing the given
78
- # arguments.
79
- #
80
- # #method_missing
81
- # : Method called when an undefined method is called on `self`.
82
- #
83
- # #singleton_method_added
84
- # : Method called when a singleton method is added to `self`.
85
- #
86
- # #singleton_method_removed
87
- # : Method called when a singleton method is added removed from `self`.
88
- #
89
- # #singleton_method_undefined
90
- # : Method called when a singleton method is undefined in `self`.
52
+ # * ::new: Returns a new BasicObject instance.
53
+ # * #!: Returns the boolean negation of `self`: `true` or `false`.
54
+ # * #!=: Returns whether `self` and the given object are *not* equal.
55
+ # * #==: Returns whether `self` and the given object are equivalent.
56
+ # * #__id__: Returns the integer object identifier for `self`.
57
+ # * #__send__: Calls the method identified by the given symbol.
58
+ # * #equal?: Returns whether `self` and the given object are the same object.
59
+ # * #instance_eval: Evaluates the given string or block in the context of
60
+ # `self`.
61
+ # * #instance_exec: Executes the given block in the context of `self`, passing
62
+ # the given arguments.
91
63
  #
92
64
  class BasicObject
93
65
  # <!--
data/core/binding.rbs CHANGED
@@ -52,7 +52,7 @@ class Binding
52
52
 
53
53
  # <!--
54
54
  # rdoc-file=lib/irb.rb
55
- # - irb()
55
+ # - irb(show_code: true)
56
56
  # -->
57
57
  # Opens an IRB session where `binding.irb` is called which allows for
58
58
  # interactive debugging. You can call any methods or variables available in the
data/core/builtin.rbs CHANGED
@@ -14,6 +14,10 @@ interface _ToS
14
14
  def to_s: () -> String
15
15
  end
16
16
 
17
+ interface _ToF
18
+ def to_f: () -> Float
19
+ end
20
+
17
21
  interface _ToStr
18
22
  def to_str: () -> String
19
23
  end
@@ -34,6 +38,10 @@ interface _Each[out A]
34
38
  def each: () { (A) -> void } -> void
35
39
  end
36
40
 
41
+ interface _EachEntry[out A]
42
+ def each_entry: () { (A) -> void } -> self
43
+ end
44
+
37
45
  interface _Reader
38
46
  def read: (?int? length, ?string outbuf) -> String?
39
47
  end
data/core/class.rbs CHANGED
@@ -106,6 +106,24 @@ class Class < Module
106
106
  #
107
107
  def allocate: () -> untyped
108
108
 
109
+ # <!--
110
+ # rdoc-file=object.c
111
+ # - attached_object -> object
112
+ # -->
113
+ # Returns the object for which the receiver is the singleton class.
114
+ #
115
+ # Raises an TypeError if the class is not a singleton class.
116
+ #
117
+ # class Foo; end
118
+ #
119
+ # Foo.singleton_class.attached_object #=> Foo
120
+ # Foo.attached_object #=> TypeError: `Foo' is not a singleton class
121
+ # Foo.new.singleton_class.attached_object #=> #<Foo:0x000000010491a370>
122
+ # TrueClass.attached_object #=> TypeError: `TrueClass' is not a singleton class
123
+ # NilClass.attached_object #=> TypeError: `NilClass' is not a singleton class
124
+ #
125
+ def attached_object: () -> untyped
126
+
109
127
  # <!--
110
128
  # rdoc-file=object.c
111
129
  # - inherited(subclass)
@@ -160,6 +178,25 @@ class Class < Module
160
178
  # B.subclasses #=> [C]
161
179
  # C.subclasses #=> []
162
180
  #
181
+ # Anonymous subclasses (not associated with a constant) are returned, too:
182
+ #
183
+ # c = Class.new(A)
184
+ # A.subclasses # => [#<Class:0x00007f003c77bd78>, D, B]
185
+ #
186
+ # Note that the parent does not hold references to subclasses and doesn't
187
+ # prevent them from being garbage collected. This means that the subclass might
188
+ # disappear when all references to it are dropped:
189
+ #
190
+ # # drop the reference to subclass, it can be garbage-collected now
191
+ # c = nil
192
+ #
193
+ # A.subclasses
194
+ # # It can be
195
+ # # => [#<Class:0x00007f003c77bd78>, D, B]
196
+ # # ...or just
197
+ # # => [D, B]
198
+ # # ...depending on whether garbage collector was run
199
+ #
163
200
  def subclasses: () -> Array[Class]
164
201
 
165
202
  # <!--
data/core/comparable.rbs CHANGED
@@ -37,24 +37,13 @@
37
37
  #
38
38
  # Module Comparable provides these methods, all of which use method `<=>`:
39
39
  #
40
- # [<](#method-i-3C)
41
- # : Returns whether `self` is less than the given object.
42
- #
43
- # [<=](#method-i-3C-3D)
44
- # : Returns whether `self` is less than or equal to the given object.
45
- #
46
- # [==](#method-i-3D-3D)
47
- # : Returns whether `self` is equal to the given object.
48
- #
49
- # [>](#method-i-3E)
50
- # : Returns whether `self` is greater than or equal to the given object.
51
- #
52
- # [>=](#method-i-3E-3D)
53
- # : Returns whether `self` is greater than the given object.
54
- #
55
- # * #between? Returns `true` if `self` is between two given objects.
56
- # #clamp
57
- # : For given objects `min` and `max`, or range `(min..max)`, returns:
40
+ # * #<: Returns whether `self` is less than the given object.
41
+ # * #<=: Returns whether `self` is less than or equal to the given object.
42
+ # * #==: Returns whether `self` is equal to the given object.
43
+ # * #>: Returns whether `self` is greater than or equal to the given object.
44
+ # * #>=: Returns whether `self` is greater than the given object.
45
+ # * #between?: Returns `true` if `self` is between two given objects.
46
+ # * #clamp: For given objects `min` and `max`, or range `(min..max)`, returns:
58
47
  #
59
48
  # * `min` if `(self <=> min) < 0`.
60
49
  # * `max` if `(self <=> max) > 0`.
data/core/complex.rbs CHANGED
@@ -5,12 +5,12 @@
5
5
  #
6
6
  # You can create a Complex object explicitly with:
7
7
  #
8
- # * A [complex literal](doc/syntax/literals_rdoc.html#label-Complex+Literals).
8
+ # * A [complex literal](rdoc-ref:syntax/literals.rdoc@Complex+Literals).
9
9
  #
10
10
  #
11
11
  # You can convert certain objects to Complex objects with:
12
12
  #
13
- # * Method [Complex](Kernel.html#method-i-Complex).
13
+ # * Method #Complex.
14
14
  #
15
15
  #
16
16
  # Complex object can be created as literal, and also by using Kernel#Complex,
data/core/data.rbs ADDED
@@ -0,0 +1,419 @@
1
+ # <!-- rdoc-file=struct.c -->
2
+ # Class Data provides a convenient way to define simple classes for value-alike
3
+ # objects.
4
+ #
5
+ # The simplest example of usage:
6
+ #
7
+ # Measure = Data.define(:amount, :unit)
8
+ #
9
+ # # Positional arguments constructor is provided
10
+ # distance = Measure.new(100, 'km')
11
+ # #=> #<data Measure amount=100, unit="km">
12
+ #
13
+ # # Keyword arguments constructor is provided
14
+ # weight = Measure.new(amount: 50, unit: 'kg')
15
+ # #=> #<data Measure amount=50, unit="kg">
16
+ #
17
+ # # Alternative form to construct an object:
18
+ # speed = Measure[10, 'mPh']
19
+ # #=> #<data Measure amount=10, unit="mPh">
20
+ #
21
+ # # Works with keyword arguments, too:
22
+ # area = Measure[amount: 1.5, unit: 'm^2']
23
+ # #=> #<data Measure amount=1.5, unit="m^2">
24
+ #
25
+ # # Argument accessors are provided:
26
+ # distance.amount #=> 100
27
+ # distance.unit #=> "km"
28
+ #
29
+ # Constructed object also has a reasonable definitions of #== operator, #to_h
30
+ # hash conversion, and #deconstruct/#deconstruct_keys to be used in pattern
31
+ # matching.
32
+ #
33
+ # ::define method accepts an optional block and evaluates it in the context of
34
+ # the newly defined class. That allows to define additional methods:
35
+ #
36
+ # Measure = Data.define(:amount, :unit) do
37
+ # def <=>(other)
38
+ # return unless other.is_a?(self.class) && other.unit == unit
39
+ # amount <=> other.amount
40
+ # end
41
+ #
42
+ # include Comparable
43
+ # end
44
+ #
45
+ # Measure[3, 'm'] < Measure[5, 'm'] #=> true
46
+ # Measure[3, 'm'] < Measure[5, 'kg']
47
+ # # comparison of Measure with Measure failed (ArgumentError)
48
+ #
49
+ # Data provides no member writers, or enumerators: it is meant to be a storage
50
+ # for immutable atomic values. But note that if some of data members is of a
51
+ # mutable class, Data does no additional immutability enforcement:
52
+ #
53
+ # Event = Data.define(:time, :weekdays)
54
+ # event = Event.new('18:00', %w[Tue Wed Fri])
55
+ # #=> #<data Event time="18:00", weekdays=["Tue", "Wed", "Fri"]>
56
+ #
57
+ # # There is no #time= or #weekdays= accessors, but changes are
58
+ # # still possible:
59
+ # event.weekdays << 'Sat'
60
+ # event
61
+ # #=> #<data Event time="18:00", weekdays=["Tue", "Wed", "Fri", "Sat"]>
62
+ #
63
+ # See also Struct, which is a similar concept, but has more container-alike API,
64
+ # allowing to change contents of the object and enumerate it.
65
+ #
66
+ class Data
67
+ # <!--
68
+ # rdoc-file=struct.c
69
+ # - define(name, *symbols) -> class
70
+ # - define(*symbols) -> class
71
+ # -->
72
+ # Defines a new Data class. If the first argument is a string, the class is
73
+ # stored in `Data::<name>` constant.
74
+ #
75
+ # measure = Data.define(:amount, :unit)
76
+ # #=> #<Class:0x00007f70c6868498>
77
+ # measure.new(1, 'km')
78
+ # #=> #<data amount=1, unit="km">
79
+ #
80
+ # # It you store the new class in the constant, it will
81
+ # # affect #inspect and will be more natural to use:
82
+ # Measure = Data.define(:amount, :unit)
83
+ # #=> Measure
84
+ # Measure.new(1, 'km')
85
+ # #=> #<data Measure amount=1, unit="km">
86
+ #
87
+ # Note that member-less Data is acceptable and might be a useful technique for
88
+ # defining several homogenous data classes, like
89
+ #
90
+ # class HTTPFetcher
91
+ # Response = Data.define(:body)
92
+ # NotFound = Data.define
93
+ # # ... implementation
94
+ # end
95
+ #
96
+ # Now, different kinds of responses from `HTTPFetcher` would have consistent
97
+ # representation:
98
+ #
99
+ # #<data HTTPFetcher::Response body="<html...">
100
+ # #<data HTTPFetcher::NotFound>
101
+ #
102
+ # And are convenient to use in pattern matching:
103
+ #
104
+ # case fetcher.get(url)
105
+ # in HTTPFetcher::Response(body)
106
+ # # process body variable
107
+ # in HTTPFetcher::NotFound
108
+ # # handle not found case
109
+ # end
110
+ #
111
+ def self.define: [KLASS < _DataClass] (*Symbol) ?{ (KLASS) [self: KLASS] -> void } -> KLASS
112
+
113
+ interface _DataClass
114
+ # <!--
115
+ # rdoc-file=struct.c
116
+ # - new(*args) -> instance
117
+ # - new(**kwargs) -> instance
118
+ # - ::[](*args) -> instance
119
+ # - ::[](**kwargs) -> instance
120
+ # -->
121
+ # Constructors for classes defined with ::define accept both positional and
122
+ # keyword arguments.
123
+ #
124
+ # Measure = Data.define(:amount, :unit)
125
+ #
126
+ # Measure.new(1, 'km')
127
+ # #=> #<data Measure amount=1, unit="km">
128
+ # Measure.new(amount: 1, unit: 'km')
129
+ # #=> #<data Measure amount=1, unit="km">
130
+ #
131
+ # # Alternative shorter intialization with []
132
+ # Measure[1, 'km']
133
+ # #=> #<data Measure amount=1, unit="km">
134
+ # Measure[amount: 1, unit: 'km']
135
+ # #=> #<data Measure amount=1, unit="km">
136
+ #
137
+ # All arguments are mandatory (unlike Struct), and converted to keyword
138
+ # arguments:
139
+ #
140
+ # Measure.new(amount: 1)
141
+ # # in `initialize': missing keyword: :unit (ArgumentError)
142
+ #
143
+ # Measure.new(1)
144
+ # # in `initialize': missing keyword: :unit (ArgumentError)
145
+ #
146
+ # Note that `Measure#initialize` always receives keyword arguments, and that
147
+ # mandatory arguments are checked in `initialize`, not in `new`. This can be
148
+ # important for redefining initialize in order to convert arguments or provide
149
+ # defaults:
150
+ #
151
+ # Measure = Data.define(:amount, :unit) do
152
+ # NONE = Data.define
153
+ #
154
+ # def initialize(amount:, unit: NONE.new)
155
+ # super(amount: Float(amount), unit:)
156
+ # end
157
+ # end
158
+ #
159
+ # Measure.new('10', 'km') # => #<data Measure amount=10.0, unit="km">
160
+ # Measure.new(10_000) # => #<data Measure amount=10000.0, unit=#<data NONE>>
161
+ #
162
+ %a{annotate:rdoc:copy:Data.new}
163
+ def new: (*untyped) -> Data
164
+ | (**untyped) -> Data
165
+
166
+ %a{annotate:rdoc:copy:Data.[]}
167
+ def []: (*untyped) -> Data
168
+ | (**untyped) -> Data
169
+
170
+ # <!--
171
+ # rdoc-file=struct.c
172
+ # - DataClass::members -> array_of_symbols
173
+ # -->
174
+ # Returns an array of member names of the data class:
175
+ #
176
+ # Measure = Data.define(:amount, :unit)
177
+ # Measure.members # => [:amount, :unit]
178
+ #
179
+ %a{annotate:rdoc:copy:Data.members}
180
+ def members: () -> Array[Symbol]
181
+ end
182
+
183
+ %a{annotate:rdoc:skip}
184
+ def self.new: () -> bot
185
+
186
+ def self.allocate: () -> bot
187
+
188
+ public
189
+
190
+ # <!--
191
+ # rdoc-file=struct.c
192
+ # - self == other -> true or false
193
+ # -->
194
+ # Returns `true` if `other` is the same class as `self`, and all members are
195
+ # equal.
196
+ #
197
+ # Examples:
198
+ #
199
+ # Measure = Data.define(:amount, :unit)
200
+ #
201
+ # Measure[1, 'km'] == Measure[1, 'km'] #=> true
202
+ # Measure[1, 'km'] == Measure[2, 'km'] #=> false
203
+ # Measure[1, 'km'] == Measure[1, 'm'] #=> false
204
+ #
205
+ # Measurement = Data.define(:amount, :unit)
206
+ # # Even though Measurement and Measure have the same "shape"
207
+ # # their instances are never equal
208
+ # Measure[1, 'km'] == Measurement[1, 'km'] #=> false
209
+ #
210
+ def ==: (untyped) -> bool
211
+
212
+ # <!--
213
+ # rdoc-file=struct.c
214
+ # - deconstruct -> array
215
+ # -->
216
+ # Returns the values in `self` as an array, to use in pattern matching:
217
+ #
218
+ # Measure = Data.define(:amount, :unit)
219
+ #
220
+ # distance = Measure[10, 'km']
221
+ # distance.deconstruct #=> [10, "km"]
222
+ #
223
+ # # usage
224
+ # case distance
225
+ # in n, 'km' # calls #deconstruct underneath
226
+ # puts "It is #{n} kilometers away"
227
+ # else
228
+ # puts "Don't know how to handle it"
229
+ # end
230
+ # # prints "It is 10 kilometers away"
231
+ #
232
+ # Or, with checking the class, too:
233
+ #
234
+ # case distance
235
+ # in Measure(n, 'km')
236
+ # puts "It is #{n} kilometers away"
237
+ # # ...
238
+ # end
239
+ #
240
+ def deconstruct: () -> Array[untyped]
241
+
242
+ # <!--
243
+ # rdoc-file=struct.c
244
+ # - deconstruct_keys(array_of_names_or_nil) -> hash
245
+ # -->
246
+ # Returns a hash of the name/value pairs, to use in pattern matching.
247
+ #
248
+ # Measure = Data.define(:amount, :unit)
249
+ #
250
+ # distance = Measure[10, 'km']
251
+ # distance.deconstruct_keys(nil) #=> {:amount=>10, :unit=>"km"}
252
+ # distance.deconstruct_keys([:amount]) #=> {:amount=>10}
253
+ #
254
+ # # usage
255
+ # case distance
256
+ # in amount:, unit: 'km' # calls #deconstruct_keys underneath
257
+ # puts "It is #{amount} kilometers away"
258
+ # else
259
+ # puts "Don't know how to handle it"
260
+ # end
261
+ # # prints "It is 10 kilometers away"
262
+ #
263
+ # Or, with checking the class, too:
264
+ #
265
+ # case distance
266
+ # in Measure(amount:, unit: 'km')
267
+ # puts "It is #{amount} kilometers away"
268
+ # # ...
269
+ # end
270
+ #
271
+ def deconstruct_keys: (?Array[Symbol]?) -> Hash[Symbol, untyped]
272
+
273
+ # <!--
274
+ # rdoc-file=struct.c
275
+ # - self.eql?(other) -> true or false
276
+ # -->
277
+ # Equality check that is used when two items of data are keys of a Hash.
278
+ #
279
+ # The subtle difference with #== is that members are also compared with their
280
+ # #eql? method, which might be important in some cases:
281
+ #
282
+ # Measure = Data.define(:amount, :unit)
283
+ #
284
+ # Measure[1, 'km'] == Measure[1.0, 'km'] #=> true, they are equal as values
285
+ # # ...but...
286
+ # Measure[1, 'km'].eql? Measure[1.0, 'km'] #=> false, they represent different hash keys
287
+ #
288
+ # See also Object#eql? for further explanations of the method usage.
289
+ #
290
+ def eql?: (untyped) -> bool
291
+
292
+ # <!--
293
+ # rdoc-file=struct.c
294
+ # - hash -> integer
295
+ # -->
296
+ # Redefines Object#hash (used to distinguish objects as Hash keys) so that data
297
+ # objects of the same class with same content would have the same `hash` value,
298
+ # and represented the same Hash key.
299
+ #
300
+ # Measure = Data.define(:amount, :unit)
301
+ #
302
+ # Measure[1, 'km'].hash == Measure[1, 'km'].hash #=> true
303
+ # Measure[1, 'km'].hash == Measure[10, 'km'].hash #=> false
304
+ # Measure[1, 'km'].hash == Measure[1, 'm'].hash #=> false
305
+ # Measure[1, 'km'].hash == Measure[1.0, 'km'].hash #=> false
306
+ #
307
+ # # Structurally similar data class, but shouldn't be considered
308
+ # # the same hash key
309
+ # Measurement = Data.define(:amount, :unit)
310
+ #
311
+ # Measure[1, 'km'].hash == Measurement[1, 'km'].hash #=> false
312
+ #
313
+ def hash: () -> Integer
314
+
315
+ # <!--
316
+ # rdoc-file=struct.c
317
+ # - inspect -> string
318
+ # - to_s -> string
319
+ # -->
320
+ # Returns a string representation of `self`:
321
+ #
322
+ # Measure = Data.define(:amount, :unit)
323
+ #
324
+ # distance = Measure[10, 'km']
325
+ #
326
+ # p distance # uses #inspect underneath
327
+ # #<data Measure amount=10, unit="km">
328
+ #
329
+ # puts distance # uses #to_s underneath, same representation
330
+ # #<data Measure amount=10, unit="km">
331
+ #
332
+ def inspect: () -> String
333
+
334
+ # <!--
335
+ # rdoc-file=struct.c
336
+ # - members -> array_of_symbols
337
+ # -->
338
+ # Returns the member names from `self` as an array:
339
+ #
340
+ # Measure = Data.define(:amount, :unit)
341
+ # distance = Measure[10, 'km']
342
+ #
343
+ # distance.members #=> [:amount, :unit]
344
+ #
345
+ def members: () -> Array[Symbol]
346
+
347
+ # <!--
348
+ # rdoc-file=struct.c
349
+ # - to_h -> hash
350
+ # - to_h {|name, value| ... } -> hash
351
+ # -->
352
+ # Returns Hash representation of the data object.
353
+ #
354
+ # Measure = Data.define(:amount, :unit)
355
+ # distance = Measure[10, 'km']
356
+ #
357
+ # distance.to_h
358
+ # #=> {:amount=>10, :unit=>"km"}
359
+ #
360
+ # Like Enumerable#to_h, if the block is provided, it is expected to produce
361
+ # key-value pairs to construct a hash:
362
+ #
363
+ # distance.to_h { |name, val| [name.to_s, val.to_s] }
364
+ # #=> {"amount"=>"10", "unit"=>"km"}
365
+ #
366
+ # Note that there is a useful symmetry between #to_h and #initialize:
367
+ #
368
+ # distance2 = Measure.new(**distance.to_h)
369
+ # #=> #<data Measure amount=10, unit="km">
370
+ # distance2 == distance
371
+ # #=> true
372
+ #
373
+ def to_h: () -> Hash[Symbol, untyped]
374
+
375
+ # <!-- rdoc-file=struct.c -->
376
+ # Returns a string representation of `self`:
377
+ #
378
+ # Measure = Data.define(:amount, :unit)
379
+ #
380
+ # distance = Measure[10, 'km']
381
+ #
382
+ # p distance # uses #inspect underneath
383
+ # #<data Measure amount=10, unit="km">
384
+ #
385
+ # puts distance # uses #to_s underneath, same representation
386
+ # #<data Measure amount=10, unit="km">
387
+ #
388
+ alias to_s inspect
389
+
390
+ # <!--
391
+ # rdoc-file=struct.c
392
+ # - with(**kwargs) -> instance
393
+ # -->
394
+ # Returns a shallow copy of `self` --- the instance variables of `self` are
395
+ # copied, but not the objects they reference.
396
+ #
397
+ # If the method is supplied any keyword arguments, the copy will be created with
398
+ # the respective field values updated to use the supplied keyword argument
399
+ # values. Note that it is an error to supply a keyword that the Data class does
400
+ # not have as a member.
401
+ #
402
+ # Point = Data.define(:x, :y)
403
+ #
404
+ # origin = Point.new(x: 0, y: 0)
405
+ #
406
+ # up = origin.with(x: 1)
407
+ # right = origin.with(y: 1)
408
+ # up_and_right = up.with(y: 1)
409
+ #
410
+ # p origin # #<data Point x=0, y=0>
411
+ # p up # #<data Point x=1, y=0>
412
+ # p right # #<data Point x=0, y=1>
413
+ # p up_and_right # #<data Point x=1, y=1>
414
+ #
415
+ # out = origin.with(z: 1) # ArgumentError: unknown keyword: :z
416
+ # some_point = origin.with(1, 2) # ArgumentError: expected keyword arguments, got positional arguments
417
+ #
418
+ def with: (**untyped) -> instance
419
+ end