rbs 0.14.0 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +8 -4
  3. data/CHANGELOG.md +35 -0
  4. data/Gemfile +1 -0
  5. data/README.md +1 -1
  6. data/Rakefile +19 -1
  7. data/Steepfile +0 -1
  8. data/bin/test_runner.rb +15 -1
  9. data/{stdlib/builtin → core}/array.rbs +124 -120
  10. data/{stdlib/builtin → core}/basic_object.rbs +0 -0
  11. data/{stdlib/builtin → core}/binding.rbs +0 -0
  12. data/core/builtin.rbs +70 -0
  13. data/{stdlib/builtin → core}/class.rbs +0 -0
  14. data/{stdlib/builtin → core}/comparable.rbs +0 -0
  15. data/{stdlib/builtin → core}/complex.rbs +0 -0
  16. data/{stdlib/builtin → core}/constants.rbs +0 -0
  17. data/{stdlib/builtin → core}/data.rbs +0 -0
  18. data/{stdlib/builtin → core}/deprecated.rbs +0 -0
  19. data/{stdlib/builtin → core}/dir.rbs +1 -1
  20. data/{stdlib/builtin → core}/encoding.rbs +0 -0
  21. data/{stdlib/builtin → core}/enumerable.rbs +67 -60
  22. data/{stdlib/builtin → core}/enumerator.rbs +5 -5
  23. data/{stdlib/builtin → core}/errno.rbs +0 -0
  24. data/{stdlib/builtin → core}/errors.rbs +1 -1
  25. data/{stdlib/builtin → core}/exception.rbs +0 -0
  26. data/{stdlib/builtin → core}/false_class.rbs +0 -0
  27. data/{stdlib/builtin → core}/fiber.rbs +0 -0
  28. data/{stdlib/builtin → core}/fiber_error.rbs +0 -0
  29. data/{stdlib/builtin → core}/file.rbs +0 -0
  30. data/{stdlib/builtin → core}/file_test.rbs +0 -0
  31. data/{stdlib/builtin → core}/float.rbs +0 -0
  32. data/{stdlib/builtin → core}/gc.rbs +2 -2
  33. data/{stdlib/builtin → core}/hash.rbs +15 -15
  34. data/{stdlib/builtin → core}/integer.rbs +0 -0
  35. data/{stdlib/builtin → core}/io.rbs +6 -6
  36. data/{stdlib/builtin → core}/kernel.rbs +1 -85
  37. data/{stdlib/builtin → core}/marshal.rbs +0 -0
  38. data/{stdlib/builtin → core}/match_data.rbs +0 -0
  39. data/{stdlib/builtin → core}/math.rbs +0 -0
  40. data/{stdlib/builtin → core}/method.rbs +0 -0
  41. data/{stdlib/builtin → core}/module.rbs +13 -13
  42. data/{stdlib/builtin → core}/nil_class.rbs +0 -0
  43. data/{stdlib/builtin → core}/numeric.rbs +0 -0
  44. data/{stdlib/builtin → core}/object.rbs +1 -1
  45. data/core/object_space.rbs +98 -0
  46. data/{stdlib/builtin → core}/proc.rbs +0 -0
  47. data/{stdlib/builtin → core}/process.rbs +0 -0
  48. data/{stdlib/builtin → core}/random.rbs +1 -1
  49. data/{stdlib/builtin → core}/range.rbs +3 -3
  50. data/{stdlib/builtin → core}/rational.rbs +0 -0
  51. data/{stdlib/builtin → core}/rb_config.rbs +0 -0
  52. data/{stdlib/builtin → core}/regexp.rbs +0 -0
  53. data/{stdlib/builtin → core}/ruby_vm.rbs +0 -0
  54. data/{stdlib/builtin → core}/signal.rbs +0 -0
  55. data/{stdlib/builtin → core}/string.rbs +6 -6
  56. data/{stdlib/builtin → core}/string_io.rbs +7 -7
  57. data/{stdlib/builtin → core}/struct.rbs +2 -2
  58. data/{stdlib/builtin → core}/symbol.rbs +1 -1
  59. data/{stdlib/builtin → core}/thread.rbs +4 -4
  60. data/{stdlib/builtin → core}/thread_group.rbs +0 -0
  61. data/{stdlib/builtin → core}/time.rbs +0 -0
  62. data/{stdlib/builtin → core}/trace_point.rbs +0 -0
  63. data/{stdlib/builtin → core}/true_class.rbs +1 -1
  64. data/{stdlib/builtin → core}/unbound_method.rbs +0 -0
  65. data/{stdlib/builtin → core}/warning.rbs +0 -0
  66. data/docs/repo.md +125 -0
  67. data/docs/syntax.md +50 -6
  68. data/lib/rbs.rb +1 -0
  69. data/lib/rbs/cli.rb +105 -103
  70. data/lib/rbs/definition.rb +9 -4
  71. data/lib/rbs/definition_builder.rb +50 -17
  72. data/lib/rbs/environment_loader.rb +79 -105
  73. data/lib/rbs/environment_walker.rb +70 -35
  74. data/lib/rbs/parser.rb +404 -397
  75. data/lib/rbs/parser.y +18 -9
  76. data/lib/rbs/prototype/rb.rb +186 -25
  77. data/lib/rbs/prototype/runtime.rb +18 -7
  78. data/lib/rbs/repository.rb +121 -0
  79. data/lib/rbs/test/hook.rb +27 -15
  80. data/lib/rbs/test/setup.rb +5 -3
  81. data/lib/rbs/test/tester.rb +4 -1
  82. data/lib/rbs/test/type_check.rb +16 -5
  83. data/lib/rbs/type_name.rb +2 -1
  84. data/lib/rbs/vendorer.rb +38 -16
  85. data/lib/rbs/version.rb +1 -1
  86. data/sig/cli.rbs +58 -0
  87. data/sig/constant_table.rbs +1 -1
  88. data/sig/declarations.rbs +1 -1
  89. data/sig/definition.rbs +9 -4
  90. data/sig/definition_builder.rbs +4 -1
  91. data/sig/environment_loader.rbs +92 -46
  92. data/sig/members.rbs +2 -2
  93. data/sig/method_types.rbs +1 -1
  94. data/sig/namespace.rbs +1 -1
  95. data/sig/polyfill.rbs +42 -0
  96. data/sig/rbs.rbs +8 -0
  97. data/sig/repository.rbs +79 -0
  98. data/sig/vendorer.rbs +44 -0
  99. data/stdlib/abbrev/{abbrev.rbs → 0/abbrev.rbs} +0 -0
  100. data/stdlib/base64/{base64.rbs → 0/base64.rbs} +1 -1
  101. data/stdlib/benchmark/{benchmark.rbs → 0/benchmark.rbs} +0 -0
  102. data/stdlib/{bigdecimal/math → bigdecimal-math/0}/big_math.rbs +0 -0
  103. data/stdlib/bigdecimal/{big_decimal.rbs → 0/big_decimal.rbs} +0 -0
  104. data/stdlib/coverage/{coverage.rbs → 0/coverage.rbs} +2 -2
  105. data/stdlib/csv/{csv.rbs → 0/csv.rbs} +4 -4
  106. data/stdlib/date/{date.rbs → 0/date.rbs} +2 -2
  107. data/stdlib/date/{date_time.rbs → 0/date_time.rbs} +1 -1
  108. data/stdlib/dbm/0/dbm.rbs +277 -0
  109. data/stdlib/erb/{erb.rbs → 0/erb.rbs} +0 -0
  110. data/stdlib/fiber/{fiber.rbs → 0/fiber.rbs} +0 -0
  111. data/stdlib/find/{find.rbs → 0/find.rbs} +2 -2
  112. data/stdlib/forwardable/{forwardable.rbs → 0/forwardable.rbs} +0 -0
  113. data/stdlib/ipaddr/{ipaddr.rbs → 0/ipaddr.rbs} +0 -0
  114. data/stdlib/json/{json.rbs → 0/json.rbs} +0 -0
  115. data/stdlib/logger/{formatter.rbs → 0/formatter.rbs} +0 -0
  116. data/stdlib/logger/{log_device.rbs → 0/log_device.rbs} +1 -1
  117. data/stdlib/logger/{logger.rbs → 0/logger.rbs} +1 -1
  118. data/stdlib/logger/{period.rbs → 0/period.rbs} +0 -0
  119. data/stdlib/logger/{severity.rbs → 0/severity.rbs} +0 -0
  120. data/stdlib/mutex_m/{mutex_m.rbs → 0/mutex_m.rbs} +0 -0
  121. data/stdlib/pathname/{pathname.rbs → 0/pathname.rbs} +39 -39
  122. data/stdlib/prime/{integer-extension.rbs → 0/integer-extension.rbs} +0 -0
  123. data/stdlib/prime/{prime.rbs → 0/prime.rbs} +1 -1
  124. data/stdlib/pstore/0/pstore.rbs +287 -0
  125. data/stdlib/pty/{pty.rbs → 0/pty.rbs} +1 -1
  126. data/stdlib/securerandom/{securerandom.rbs → 0/securerandom.rbs} +0 -0
  127. data/stdlib/set/{set.rbs → 0/set.rbs} +10 -10
  128. data/stdlib/singleton/0/singleton.rbs +111 -0
  129. data/stdlib/tmpdir/{tmpdir.rbs → 0/tmpdir.rbs} +0 -0
  130. data/stdlib/tsort/0/cyclic.rbs +4 -0
  131. data/stdlib/tsort/0/interfaces.rbs +19 -0
  132. data/stdlib/tsort/0/tsort.rbs +363 -0
  133. data/stdlib/uri/{file.rbs → 0/file.rbs} +0 -0
  134. data/stdlib/uri/{generic.rbs → 0/generic.rbs} +1 -1
  135. data/stdlib/uri/{http.rbs → 0/http.rbs} +0 -0
  136. data/stdlib/uri/{https.rbs → 0/https.rbs} +0 -0
  137. data/stdlib/uri/{ldap.rbs → 0/ldap.rbs} +0 -0
  138. data/stdlib/uri/{ldaps.rbs → 0/ldaps.rbs} +0 -0
  139. data/stdlib/yaml/0/dbm.rbs +221 -0
  140. data/stdlib/yaml/0/store.rbs +53 -0
  141. data/stdlib/zlib/{zlib.rbs → 0/zlib.rbs} +0 -0
  142. data/steep/Gemfile.lock +9 -9
  143. metadata +108 -94
  144. data/stdlib/builtin/builtin.rbs +0 -42
@@ -137,7 +137,7 @@ class Prime
137
137
  class PseudoPrimeGenerator
138
138
  def initialize: (?Integer?) -> void
139
139
 
140
- include Enumerable[Integer, void]
140
+ include Enumerable[Integer]
141
141
 
142
142
  attr_accessor upper_bound (): Integer?
143
143
 
@@ -0,0 +1,287 @@
1
+ # PStore implements a file based persistence mechanism based on a Hash. User
2
+ # code can store hierarchies of Ruby objects (values) into the data store file
3
+ # by name (keys). An object hierarchy may be just a single object. User code
4
+ # may later read values back from the data store or even update data, as needed.
5
+ #
6
+ # The transactional behavior ensures that any changes succeed or fail together.
7
+ # This can be used to ensure that the data store is not left in a transitory
8
+ # state, where some values were updated but others were not.
9
+ #
10
+ # Behind the scenes, Ruby objects are stored to the data store file with
11
+ # Marshal. That carries the usual limitations. Proc objects cannot be
12
+ # marshalled, for example.
13
+ #
14
+ # ## Usage example:
15
+ #
16
+ # require "pstore"
17
+ #
18
+ # # a mock wiki object...
19
+ # class WikiPage
20
+ # def initialize( page_name, author, contents )
21
+ # @page_name = page_name
22
+ # @revisions = Array.new
23
+ #
24
+ # add_revision(author, contents)
25
+ # end
26
+ #
27
+ # attr_reader :page_name
28
+ #
29
+ # def add_revision( author, contents )
30
+ # @revisions << { :created => Time.now,
31
+ # :author => author,
32
+ # :contents => contents }
33
+ # end
34
+ #
35
+ # def wiki_page_references
36
+ # [@page_name] + @revisions.last[:contents].scan(/\b(?:[A-Z]+[a-z]+){2,}/)
37
+ # end
38
+ #
39
+ # # ...
40
+ # end
41
+ #
42
+ # # create a new page...
43
+ # home_page = WikiPage.new( "HomePage", "James Edward Gray II",
44
+ # "A page about the JoysOfDocumentation..." )
45
+ #
46
+ # # then we want to update page data and the index together, or not at all...
47
+ # wiki = PStore.new("wiki_pages.pstore")
48
+ # wiki.transaction do # begin transaction; do all of this or none of it
49
+ # # store page...
50
+ # wiki[home_page.page_name] = home_page
51
+ # # ensure that an index has been created...
52
+ # wiki[:wiki_index] ||= Array.new
53
+ # # update wiki index...
54
+ # wiki[:wiki_index].push(*home_page.wiki_page_references)
55
+ # end # commit changes to wiki data store file
56
+ #
57
+ # ### Some time later... ###
58
+ #
59
+ # # read wiki data...
60
+ # wiki.transaction(true) do # begin read-only transaction, no changes allowed
61
+ # wiki.roots.each do |data_root_name|
62
+ # p data_root_name
63
+ # p wiki[data_root_name]
64
+ # end
65
+ # end
66
+ #
67
+ # ## Transaction modes
68
+ #
69
+ # By default, file integrity is only ensured as long as the operating system
70
+ # (and the underlying hardware) doesn't raise any unexpected I/O errors. If an
71
+ # I/O error occurs while PStore is writing to its file, then the file will
72
+ # become corrupted.
73
+ #
74
+ # You can prevent this by setting *pstore.ultra_safe = true*. However, this
75
+ # results in a minor performance loss, and only works on platforms that support
76
+ # atomic file renames. Please consult the documentation for `ultra_safe` for
77
+ # details.
78
+ #
79
+ # Needless to say, if you're storing valuable data with PStore, then you should
80
+ # backup the PStore files from time to time.
81
+ #
82
+ class PStore
83
+ public
84
+
85
+ # Retrieves a value from the PStore file data, by *name*. The hierarchy of Ruby
86
+ # objects stored under that root *name* will be returned.
87
+ #
88
+ # **WARNING**: This method is only valid in a PStore#transaction. It will
89
+ # raise PStore::Error if called at any other time.
90
+ #
91
+ def []: (untyped name) -> untyped
92
+
93
+ # Stores an individual Ruby object or a hierarchy of Ruby objects in the data
94
+ # store file under the root *name*. Assigning to a *name* already in the data
95
+ # store clobbers the old data.
96
+ #
97
+ # ## Example:
98
+ #
99
+ # require "pstore"
100
+ #
101
+ # store = PStore.new("data_file.pstore")
102
+ # store.transaction do # begin transaction
103
+ # # load some data into the store...
104
+ # store[:single_object] = "My data..."
105
+ # store[:obj_hierarchy] = { "Kev Jackson" => ["rational.rb", "pstore.rb"],
106
+ # "James Gray" => ["erb.rb", "pstore.rb"] }
107
+ # end # commit changes to data store file
108
+ #
109
+ # **WARNING**: This method is only valid in a PStore#transaction and it cannot
110
+ # be read-only. It will raise PStore::Error if called at any other time.
111
+ #
112
+ def []=: (untyped name, untyped value) -> untyped
113
+
114
+ # Ends the current PStore#transaction, discarding any changes to the data store.
115
+ #
116
+ # ## Example:
117
+ #
118
+ # require "pstore"
119
+ #
120
+ # store = PStore.new("data_file.pstore")
121
+ # store.transaction do # begin transaction
122
+ # store[:one] = 1 # this change is not applied, see below...
123
+ # store[:two] = 2 # this change is not applied, see below...
124
+ #
125
+ # store.abort # end transaction here, discard all changes
126
+ #
127
+ # store[:three] = 3 # this change is never reached
128
+ # end
129
+ #
130
+ # **WARNING**: This method is only valid in a PStore#transaction. It will
131
+ # raise PStore::Error if called at any other time.
132
+ #
133
+ def abort: () -> untyped
134
+
135
+ # Ends the current PStore#transaction, committing any changes to the data store
136
+ # immediately.
137
+ #
138
+ # ## Example:
139
+ #
140
+ # require "pstore"
141
+ #
142
+ # store = PStore.new("data_file.pstore")
143
+ # store.transaction do # begin transaction
144
+ # # load some data into the store...
145
+ # store[:one] = 1
146
+ # store[:two] = 2
147
+ #
148
+ # store.commit # end transaction here, committing changes
149
+ #
150
+ # store[:three] = 3 # this change is never reached
151
+ # end
152
+ #
153
+ # **WARNING**: This method is only valid in a PStore#transaction. It will
154
+ # raise PStore::Error if called at any other time.
155
+ #
156
+ def commit: () -> nil
157
+
158
+ # Removes an object hierarchy from the data store, by *name*.
159
+ #
160
+ # **WARNING**: This method is only valid in a PStore#transaction and it cannot
161
+ # be read-only. It will raise PStore::Error if called at any other time.
162
+ #
163
+ def delete: (untyped name) -> untyped
164
+
165
+ # This method is just like PStore#[], save that you may also provide a *default*
166
+ # value for the object. In the event the specified *name* is not found in the
167
+ # data store, your *default* will be returned instead. If you do not specify a
168
+ # default, PStore::Error will be raised if the object is not found.
169
+ #
170
+ # **WARNING**: This method is only valid in a PStore#transaction. It will
171
+ # raise PStore::Error if called at any other time.
172
+ #
173
+ def fetch: (untyped name, ?untyped default) -> untyped
174
+
175
+ # Returns the path to the data store file.
176
+ #
177
+ def path: () -> untyped
178
+
179
+ # Returns true if the supplied *name* is currently in the data store.
180
+ #
181
+ # **WARNING**: This method is only valid in a PStore#transaction. It will
182
+ # raise PStore::Error if called at any other time.
183
+ #
184
+ def root?: (untyped name) -> bool
185
+
186
+ # Returns the names of all object hierarchies currently in the store.
187
+ #
188
+ # **WARNING**: This method is only valid in a PStore#transaction. It will
189
+ # raise PStore::Error if called at any other time.
190
+ #
191
+ def roots: () -> Array[untyped]
192
+
193
+ # Opens a new transaction for the data store. Code executed inside a block
194
+ # passed to this method may read and write data to and from the data store file.
195
+ #
196
+ # At the end of the block, changes are committed to the data store
197
+ # automatically. You may exit the transaction early with a call to either
198
+ # PStore#commit or PStore#abort. See those methods for details about how
199
+ # changes are handled. Raising an uncaught Exception in the block is equivalent
200
+ # to calling PStore#abort.
201
+ #
202
+ # If *read_only* is set to `true`, you will only be allowed to read from the
203
+ # data store during the transaction and any attempts to change the data will
204
+ # raise a PStore::Error.
205
+ #
206
+ # Note that PStore does not support nested transactions.
207
+ #
208
+ def transaction: (?untyped read_only) -> untyped
209
+
210
+ # Whether PStore should do its best to prevent file corruptions, even when under
211
+ # unlikely-to-occur error conditions such as out-of-space conditions and other
212
+ # unusual OS filesystem errors. Setting this flag comes at the price in the form
213
+ # of a performance loss.
214
+ #
215
+ # This flag only has effect on platforms on which file renames are atomic (e.g.
216
+ # all POSIX platforms: Linux, MacOS X, FreeBSD, etc). The default value is
217
+ # false.
218
+ #
219
+ def ultra_safe: () -> untyped
220
+
221
+ def ultra_safe=: (untyped) -> untyped
222
+
223
+ private
224
+
225
+ def dump: (untyped table) -> untyped
226
+
227
+ def empty_marshal_checksum: () -> untyped
228
+
229
+ def empty_marshal_data: () -> untyped
230
+
231
+ # Raises PStore::Error if the calling code is not in a PStore#transaction.
232
+ #
233
+ def in_transaction: () -> untyped
234
+
235
+ # Raises PStore::Error if the calling code is not in a PStore#transaction or if
236
+ # the code is in a read-only PStore#transaction.
237
+ #
238
+ def in_transaction_wr: () -> untyped
239
+
240
+ # To construct a PStore object, pass in the *file* path where you would like the
241
+ # data to be stored.
242
+ #
243
+ # PStore objects are always reentrant. But if *thread_safe* is set to true, then
244
+ # it will become thread-safe at the cost of a minor performance hit.
245
+ #
246
+ def initialize: (untyped file, ?boolish thread_safe) -> untyped
247
+
248
+ def load: (untyped content) -> untyped
249
+
250
+ # Load the given PStore file. If `read_only` is true, the unmarshalled Hash will
251
+ # be returned. If `read_only` is false, a 3-tuple will be returned: the
252
+ # unmarshalled Hash, a checksum of the data, and the size of the data.
253
+ #
254
+ def load_data: (untyped file, untyped read_only) -> untyped
255
+
256
+ def on_windows?: () -> bool
257
+
258
+ # Open the specified filename (either in read-only mode or in read-write mode)
259
+ # and lock it for reading or writing.
260
+ #
261
+ # The opened File object will be returned. If *read_only* is true, and the file
262
+ # does not exist, then nil will be returned.
263
+ #
264
+ # All exceptions are propagated.
265
+ #
266
+ def open_and_lock_file: (untyped filename, untyped read_only) -> untyped
267
+
268
+ def save_data: (untyped original_checksum, untyped original_file_size, untyped file) -> untyped
269
+
270
+ def save_data_with_atomic_file_rename_strategy: (untyped data, untyped file) -> untyped
271
+
272
+ def save_data_with_fast_strategy: (untyped data, untyped file) -> untyped
273
+ end
274
+
275
+ PStore::EMPTY_MARSHAL_CHECKSUM: String
276
+
277
+ PStore::EMPTY_MARSHAL_DATA: String
278
+
279
+ PStore::EMPTY_STRING: String
280
+
281
+ PStore::RDWR_ACCESS: Hash[untyped, untyped]
282
+
283
+ PStore::RD_ACCESS: Hash[untyped, untyped]
284
+
285
+ PStore::VERSION: String
286
+
287
+ PStore::WR_ACCESS: Hash[untyped, untyped]
@@ -66,7 +66,7 @@ module PTY
66
66
  # : If `true` and the process identified by `pid` is no longer alive a
67
67
  # PTY::ChildExited is raised.
68
68
  #
69
- def self.check: (Integer pid, ?bool raise) -> Process::Status?
69
+ def self.check: (Integer pid, ?boolish raise) -> Process::Status?
70
70
 
71
71
  alias self.getpty self.spawn
72
72
 
@@ -51,8 +51,8 @@ class Set[A]
51
51
  # Set.new(1..5) #=> #<Set: {1, 2, 3, 4, 5}>
52
52
  # Set.new([1, 2, 3]) { |x| x * x } #=> #<Set: {1, 4, 9}>
53
53
  #
54
- def initialize: (_Each[A, untyped]) -> untyped
55
- | [X] (_Each[X, untyped]) { (X) -> A } -> untyped
54
+ def initialize: (_Each[A]) -> untyped
55
+ | [X] (_Each[X]) { (X) -> A } -> untyped
56
56
  | (?nil) -> untyped
57
57
 
58
58
  # Creates a new set containing the given objects.
@@ -69,7 +69,7 @@ class Set[A]
69
69
  # Set[1, 3, 5] & Set[3, 2, 1] #=> #<Set: {3, 1}>
70
70
  # Set['a', 'b', 'z'] & ['a', 'b', 'c'] #=> #<Set: {"a", "b"}>
71
71
  #
72
- def &: (_Each[A, untyped]) -> self
72
+ def &: (_Each[A]) -> self
73
73
 
74
74
  alias intersection &
75
75
 
@@ -79,7 +79,7 @@ class Set[A]
79
79
  # Set[1, 2, 3] | Set[2, 4, 5] #=> #<Set: {1, 2, 3, 4, 5}>
80
80
  # Set[1, 5, 'z'] | (1..6) #=> #<Set: {1, 5, "z", 2, 3, 4, 6}>
81
81
  #
82
- def |: (_Each[A, untyped]) -> self
82
+ def |: (_Each[A]) -> self
83
83
 
84
84
  alias union |
85
85
 
@@ -91,7 +91,7 @@ class Set[A]
91
91
  # Set[1, 3, 5] - Set[1, 5] #=> #<Set: {3}>
92
92
  # Set['a', 'b', 'z'] - ['a', 'c'] #=> #<Set: {"b", "z"}>
93
93
  #
94
- def -: (_Each[A, untyped]) -> self
94
+ def -: (_Each[A]) -> self
95
95
 
96
96
  alias difference -
97
97
 
@@ -133,7 +133,7 @@ class Set[A]
133
133
  # Set[1, 2] ^ Set[2, 3] #=> #<Set: {3, 1}>
134
134
  # Set[1, 'b', 'c'] ^ ['b', 'd'] #=> #<Set: {"d", 1, "c"}>
135
135
  #
136
- def ^: (_Each[A, untyped]) -> self
136
+ def ^: (_Each[A]) -> self
137
137
 
138
138
  # Classifies the set by the return value of the given block and returns a hash
139
139
  # of {value => set of elements} pairs. The block is called once for each
@@ -248,7 +248,7 @@ class Set[A]
248
248
  # Merges the elements of the given enumerable object to the set and returns
249
249
  # self.
250
250
  #
251
- def merge: (_Each[A, untyped]) -> self
251
+ def merge: (_Each[A]) -> self
252
252
 
253
253
  # Returns true if the set is a subset of the given set.
254
254
  #
@@ -271,7 +271,7 @@ class Set[A]
271
271
  # set.replace([1, 2]) #=> #<Set: {1, 2}>
272
272
  # set #=> #<Set: {1, 2}>
273
273
  #
274
- def replace: (_Each[A, untyped]) -> self
274
+ def replace: (_Each[A]) -> self
275
275
 
276
276
  # Resets the internal state after modification to existing elements and returns
277
277
  # self.
@@ -288,7 +288,7 @@ class Set[A]
288
288
  # Deletes every element that appears in the given enumerable object and returns
289
289
  # self.
290
290
  #
291
- def subtract: (_Each[A, untyped]) -> self
291
+ def subtract: (_Each[A]) -> self
292
292
 
293
293
  # Converts the set to an array. The order of elements is uncertain.
294
294
  #
@@ -297,5 +297,5 @@ class Set[A]
297
297
  #
298
298
  def to_a: () -> Array[A]
299
299
 
300
- include Enumerable[A, self]
300
+ include Enumerable[A]
301
301
  end
@@ -0,0 +1,111 @@
1
+ # The Singleton module implements the Singleton pattern.
2
+ #
3
+ # ## Usage
4
+ #
5
+ # To use Singleton, include the module in your class.
6
+ #
7
+ # class Klass
8
+ # include Singleton
9
+ # # ...
10
+ # end
11
+ #
12
+ # This ensures that only one instance of Klass can be created.
13
+ #
14
+ # a,b = Klass.instance, Klass.instance
15
+ #
16
+ # a == b
17
+ # # => true
18
+ #
19
+ # Klass.new
20
+ # # => NoMethodError - new is private ...
21
+ #
22
+ # The instance is created at upon the first call of Klass.instance().
23
+ #
24
+ # class OtherKlass
25
+ # include Singleton
26
+ # # ...
27
+ # end
28
+ #
29
+ # ObjectSpace.each_object(OtherKlass){}
30
+ # # => 0
31
+ #
32
+ # OtherKlass.instance
33
+ # ObjectSpace.each_object(OtherKlass){}
34
+ # # => 1
35
+ #
36
+ # This behavior is preserved under inheritance and cloning.
37
+ #
38
+ # ## Implementation
39
+ #
40
+ # This above is achieved by:
41
+ #
42
+ # * Making Klass.new and Klass.allocate private.
43
+ #
44
+ # * Overriding Klass.inherited(sub_klass) and Klass.clone() to ensure that the
45
+ # Singleton properties are kept when inherited and cloned.
46
+ #
47
+ # * Providing the Klass.instance() method that returns the same object each
48
+ # time it is called.
49
+ #
50
+ # * Overriding Klass._load(str) to call Klass.instance().
51
+ #
52
+ # * Overriding Klass#clone and Klass#dup to raise TypeErrors to prevent
53
+ # cloning or duping.
54
+ #
55
+ #
56
+ # ## Singleton and Marshal
57
+ #
58
+ # By default Singleton's #_dump(depth) returns the empty string. Marshalling by
59
+ # default will strip state information, e.g. instance variables from the
60
+ # instance. Classes using Singleton can provide custom _load(str) and
61
+ # _dump(depth) methods to retain some of the previous state of the instance.
62
+ #
63
+ # require 'singleton'
64
+ #
65
+ # class Example
66
+ # include Singleton
67
+ # attr_accessor :keep, :strip
68
+ # def _dump(depth)
69
+ # # this strips the @strip information from the instance
70
+ # Marshal.dump(@keep, depth)
71
+ # end
72
+ #
73
+ # def self._load(str)
74
+ # instance.keep = Marshal.load(str)
75
+ # instance
76
+ # end
77
+ # end
78
+ #
79
+ # a = Example.instance
80
+ # a.keep = "keep this"
81
+ # a.strip = "get rid of this"
82
+ #
83
+ # stored_state = Marshal.dump(a)
84
+ #
85
+ # a.keep = nil
86
+ # a.strip = nil
87
+ # b = Marshal.load(stored_state)
88
+ # p a == b # => true
89
+ # p a.keep # => "keep this"
90
+ # p a.strip # => nil
91
+ module Singleton
92
+ def self.__init__: (Class klass) -> Class
93
+
94
+ def self.instance: () -> instance
95
+
96
+ public
97
+
98
+ # By default, do not retain any state when marshalling.
99
+ #
100
+ def _dump: (?Integer depth) -> String
101
+
102
+ # Raises a TypeError to prevent cloning.
103
+ #
104
+ def clone: () -> bot
105
+
106
+ # Raises a TypeError to prevent duping.
107
+ #
108
+ def dup: () -> bot
109
+ end
110
+
111
+ Singleton::VERSION: String