rbs 3.3.2 → 3.4.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -5
  3. data/.github/workflows/ruby.yml +7 -8
  4. data/.github/workflows/typecheck.yml +37 -0
  5. data/CHANGELOG.md +50 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +11 -11
  8. data/Steepfile +2 -2
  9. data/core/array.rbs +19 -49
  10. data/core/basic_object.rbs +2 -2
  11. data/core/comparable.rbs +17 -8
  12. data/core/complex.rbs +82 -43
  13. data/core/data.rbs +2 -4
  14. data/core/dir.rbs +635 -295
  15. data/core/enumerable.rbs +11 -18
  16. data/core/enumerator.rbs +37 -31
  17. data/core/errors.rbs +4 -0
  18. data/core/false_class.rbs +34 -15
  19. data/core/fiber.rbs +23 -0
  20. data/core/file.rbs +329 -120
  21. data/core/float.rbs +17 -32
  22. data/core/gc.rbs +17 -11
  23. data/core/hash.rbs +22 -44
  24. data/core/integer.rbs +82 -113
  25. data/core/io/buffer.rbs +90 -47
  26. data/core/io.rbs +39 -116
  27. data/core/kernel.rbs +442 -489
  28. data/core/match_data.rbs +55 -56
  29. data/core/module.rbs +45 -1
  30. data/core/nil_class.rbs +98 -35
  31. data/core/numeric.rbs +22 -32
  32. data/core/object_space/weak_key_map.rbs +102 -0
  33. data/core/process.rbs +1242 -655
  34. data/core/ractor.rbs +139 -120
  35. data/core/range.rbs +100 -4
  36. data/core/rational.rbs +0 -4
  37. data/core/rbs/unnamed/argf.rbs +16 -8
  38. data/core/rbs/unnamed/env_class.rbs +0 -24
  39. data/core/refinement.rbs +8 -0
  40. data/core/regexp.rbs +1149 -598
  41. data/core/ruby_vm.rbs +126 -12
  42. data/core/rubygems/platform.rbs +9 -0
  43. data/core/rubygems/rubygems.rbs +1 -1
  44. data/core/rubygems/version.rbs +5 -1
  45. data/core/set.rbs +20 -22
  46. data/core/signal.rbs +4 -4
  47. data/core/string.rbs +283 -230
  48. data/core/string_io.rbs +2 -14
  49. data/core/struct.rbs +404 -24
  50. data/core/symbol.rbs +1 -19
  51. data/core/thread.rbs +29 -12
  52. data/core/time.rbs +227 -104
  53. data/core/trace_point.rbs +2 -5
  54. data/core/true_class.rbs +54 -21
  55. data/core/warning.rbs +14 -11
  56. data/docs/data_and_struct.md +29 -0
  57. data/docs/syntax.md +3 -5
  58. data/docs/tools.md +1 -0
  59. data/ext/rbs_extension/lexer.c +643 -559
  60. data/ext/rbs_extension/lexer.re +5 -1
  61. data/ext/rbs_extension/parser.c +12 -3
  62. data/ext/rbs_extension/unescape.c +7 -47
  63. data/lib/rbs/cli/diff.rb +4 -1
  64. data/lib/rbs/cli/validate.rb +280 -0
  65. data/lib/rbs/cli.rb +2 -194
  66. data/lib/rbs/collection/config.rb +5 -6
  67. data/lib/rbs/collection/sources/git.rb +1 -1
  68. data/lib/rbs/collection.rb +1 -0
  69. data/lib/rbs/diff.rb +7 -4
  70. data/lib/rbs/errors.rb +11 -0
  71. data/lib/rbs/test/errors.rb +4 -1
  72. data/lib/rbs/test/guaranteed.rb +2 -3
  73. data/lib/rbs/test/type_check.rb +15 -10
  74. data/lib/rbs/test.rb +3 -3
  75. data/lib/rbs/types.rb +29 -0
  76. data/lib/rbs/unit_test/convertibles.rb +176 -0
  77. data/lib/rbs/unit_test/spy.rb +136 -0
  78. data/lib/rbs/unit_test/type_assertions.rb +341 -0
  79. data/lib/rbs/unit_test/with_aliases.rb +143 -0
  80. data/lib/rbs/unit_test.rb +6 -0
  81. data/lib/rbs/version.rb +1 -1
  82. data/sig/cli/validate.rbs +43 -0
  83. data/sig/diff.rbs +3 -1
  84. data/sig/errors.rbs +8 -0
  85. data/sig/rbs.rbs +1 -1
  86. data/sig/test/errors.rbs +52 -0
  87. data/sig/test/guranteed.rbs +9 -0
  88. data/sig/test/type_check.rbs +19 -0
  89. data/sig/test.rbs +82 -0
  90. data/sig/types.rbs +6 -1
  91. data/sig/unit_test/convertibles.rbs +154 -0
  92. data/sig/unit_test/spy.rbs +28 -0
  93. data/sig/unit_test/type_assertions.rbs +194 -0
  94. data/sig/unit_test/with_aliases.rbs +136 -0
  95. data/stdlib/base64/0/base64.rbs +307 -45
  96. data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
  97. data/stdlib/coverage/0/coverage.rbs +2 -2
  98. data/stdlib/csv/0/csv.rbs +25 -55
  99. data/stdlib/date/0/date.rbs +1 -43
  100. data/stdlib/date/0/date_time.rbs +1 -13
  101. data/stdlib/delegate/0/delegator.rbs +186 -0
  102. data/stdlib/delegate/0/kernel.rbs +47 -0
  103. data/stdlib/delegate/0/simple_delegator.rbs +98 -0
  104. data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
  105. data/stdlib/erb/0/erb.rbs +2 -2
  106. data/stdlib/fileutils/0/fileutils.rbs +0 -19
  107. data/stdlib/io-console/0/io-console.rbs +12 -1
  108. data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
  109. data/stdlib/json/0/json.rbs +320 -81
  110. data/stdlib/logger/0/logger.rbs +9 -5
  111. data/stdlib/monitor/0/monitor.rbs +78 -0
  112. data/stdlib/net-http/0/net-http.rbs +1880 -543
  113. data/stdlib/objspace/0/objspace.rbs +19 -13
  114. data/stdlib/openssl/0/openssl.rbs +508 -127
  115. data/stdlib/optparse/0/optparse.rbs +25 -11
  116. data/stdlib/pathname/0/pathname.rbs +1 -1
  117. data/stdlib/pp/0/pp.rbs +2 -5
  118. data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
  119. data/stdlib/pstore/0/pstore.rbs +2 -4
  120. data/stdlib/rdoc/0/comment.rbs +1 -2
  121. data/stdlib/resolv/0/resolv.rbs +4 -2
  122. data/stdlib/socket/0/socket.rbs +2 -2
  123. data/stdlib/socket/0/unix_socket.rbs +2 -2
  124. data/stdlib/strscan/0/string_scanner.rbs +3 -2
  125. data/stdlib/tempfile/0/tempfile.rbs +1 -1
  126. data/stdlib/uri/0/common.rbs +245 -123
  127. metadata +23 -4
  128. data/lib/rbs/test/spy.rb +0 -6
data/sig/test.rbs ADDED
@@ -0,0 +1,82 @@
1
+ module RBS
2
+ module Test
3
+ # Object#class
4
+ CLASS: UnboundMethod
5
+
6
+ # Module#define_method
7
+ DEFINE_METHOD: UnboundMethod
8
+
9
+ # Kernel#inspect
10
+ INSPECT: UnboundMethod
11
+
12
+ # BasicObject#instance_eval
13
+ INSTANCE_EVAL: UnboundMethod
14
+
15
+ # BasicObject#instance_exec
16
+ INSTANCE_EXEC: UnboundMethod
17
+
18
+ # Kernel#is_a?
19
+ IS_AP: UnboundMethod
20
+
21
+ # Kernel#method
22
+ METHOD: UnboundMethod
23
+
24
+ # Kernel#methods
25
+ METHODS: UnboundMethod
26
+
27
+ # Kernel#pp
28
+ PP: UnboundMethod
29
+
30
+ # Kernel#singleton_class
31
+ SINGLETON_CLASS: UnboundMethod
32
+
33
+ # Kernel#respond_to?
34
+ RESPOND_TOP: UnboundMethod
35
+
36
+ class ArgumentsReturn
37
+ type exit_type = :return | :exception | :break
38
+
39
+ attr_reader arguments: Array[untyped]
40
+
41
+ attr_reader exit_value: untyped
42
+
43
+ attr_reader exit_type: exit_type
44
+
45
+ def initialize: (arguments: Array[untyped], exit_value: untyped, exit_type: exit_type) -> void
46
+
47
+ def self.return: (arguments: Array[untyped], value: untyped) -> ArgumentsReturn
48
+
49
+ def self.exception: (arguments: Array[untyped], exception: untyped) -> ArgumentsReturn
50
+
51
+ def self.break: (arguments: Array[untyped]) -> ArgumentsReturn
52
+
53
+ def return_value: () -> untyped
54
+
55
+ def exception: () -> untyped
56
+
57
+ def return?: () -> bool
58
+
59
+ def exception?: () -> bool
60
+
61
+ def break?: () -> bool
62
+ end
63
+
64
+ class CallTrace
65
+ attr_reader method_name: Symbol
66
+
67
+ attr_reader method_call: ArgumentsReturn
68
+
69
+ attr_reader block_calls: Array[ArgumentsReturn]
70
+
71
+ attr_reader block_given: bool
72
+
73
+ def initialize: (method_name: Symbol, method_call: ArgumentsReturn, block_calls: Array[ArgumentsReturn], block_given: bool) -> void
74
+ end
75
+
76
+ attr_accessor self.suffix: String
77
+
78
+ def self.reset_suffix: () -> String
79
+
80
+ def self.call: (untyped receiver, UnboundMethod, *untyped) ?{ () -> void } -> void
81
+ end
82
+ end
data/sig/types.rbs CHANGED
@@ -53,7 +53,7 @@ module RBS
53
53
  #
54
54
  # * The function return type is a return position (`() -> void`)
55
55
  # * Generic parameter is a return position (`Enumerator[Integer, void]`)
56
- #
56
+ #
57
57
  def with_nonreturn_void?: () -> bool
58
58
  end
59
59
 
@@ -497,6 +497,11 @@ module RBS
497
497
  include NoTypeName
498
498
 
499
499
  attr_reader location: loc?
500
+
501
+ TABLE: Hash[String, String]
502
+
503
+ # Unescape string type body
504
+ def self.unescape_string: (String, bool is_double_quote) -> String
500
505
  end
501
506
  end
502
507
  end
@@ -0,0 +1,154 @@
1
+ module RBS
2
+ module UnitTest
3
+ module Convertibles
4
+ # An object that doesn't have methods excepts `__send__` and `__id__`
5
+ #
6
+ # Other methods are `undef`ed.
7
+ #
8
+ class BlankSlate < BasicObject
9
+ # Add Object methods to `self`
10
+ #
11
+ def __with_object_methods: (*Symbol methods) -> self
12
+ end
13
+
14
+ # An object with `#to_io` method
15
+ class ToIO < BlankSlate
16
+ @io: untyped
17
+
18
+ def initialize: (?untyped io) -> void
19
+
20
+ def to_io: () -> untyped
21
+ end
22
+
23
+ # An object with `#to_i` method
24
+ class ToI < BlankSlate
25
+ @value: untyped
26
+
27
+ def initialize: (?untyped value) -> void
28
+
29
+ def to_i: () -> untyped
30
+ end
31
+
32
+ # An object with `#to_int` method
33
+ class ToInt < BlankSlate
34
+ @value: untyped
35
+
36
+ def initialize: (?untyped value) -> void
37
+
38
+ def to_int: () -> untyped
39
+ end
40
+
41
+ # An object with `#to_f` method
42
+ class ToF < BlankSlate
43
+ @value: untyped
44
+
45
+ def initialize: (?untyped value) -> void
46
+
47
+ def to_f: () -> untyped
48
+ end
49
+
50
+ # An object with `#to_r` method
51
+ class ToR < BlankSlate
52
+ @value: untyped
53
+
54
+ def initialize: (?untyped value) -> void
55
+
56
+ def to_r: () -> untyped
57
+ end
58
+
59
+ # An object with `#to_c` method
60
+ class ToC < BlankSlate
61
+ @value: untyped
62
+
63
+ def initialize: (?untyped value) -> void
64
+
65
+ def to_c: () -> untyped
66
+ end
67
+
68
+ # An object with `#to_str` method
69
+ class ToStr < BlankSlate
70
+ @value: untyped
71
+
72
+ def initialize: (?untyped value) -> void
73
+
74
+ def to_str: () -> untyped
75
+ end
76
+
77
+ # An object with `#to_s` method
78
+ class ToS < BlankSlate
79
+ @value: untyped
80
+
81
+ def initialize: (?untyped value) -> void
82
+
83
+ def to_s: () -> untyped
84
+ end
85
+
86
+ # An object with `#to_sym` method
87
+ class ToSym < BlankSlate
88
+ @value: untyped
89
+
90
+ def initialize: (?untyped value) -> void
91
+
92
+ def to_sym: () -> untyped
93
+ end
94
+
95
+ # An object with `#to_a` method
96
+ class ToA < BlankSlate
97
+ @args: untyped
98
+
99
+ def initialize: (*untyped args) -> void
100
+
101
+ def to_a: () -> Array[untyped]
102
+ end
103
+
104
+ # An object with `#to_ary` method
105
+ class ToArray < BlankSlate
106
+ @args: untyped
107
+
108
+ def initialize: (*untyped args) -> void
109
+
110
+ def to_ary: () -> Array[untyped]
111
+ end
112
+
113
+ # An object with `#to_hash` method
114
+ class ToHash < BlankSlate
115
+ @hash: untyped
116
+
117
+ def initialize: (?::Hash[untyped, untyped] hash) -> void
118
+
119
+ def to_hash: () -> Hash[untyped, untyped]
120
+ end
121
+
122
+ # An object with `#to_path` method
123
+ class ToPath < BlankSlate
124
+ @value: untyped
125
+
126
+ def initialize: (?untyped value) -> void
127
+
128
+ def to_path: () -> untyped
129
+ end
130
+
131
+ # An object with `#begin`, `#end`, and `#exclude_end`
132
+ class CustomRange < BlankSlate
133
+ @exclude_end: untyped
134
+
135
+ attr_reader begin: untyped
136
+
137
+ attr_reader end: untyped
138
+
139
+ def initialize: (untyped begin_, untyped end_, ?untyped exclude_end) -> void
140
+
141
+ def exclude_end?: () -> untyped
142
+ end
143
+
144
+ # An object with `#each` method
145
+ class Each < BlankSlate
146
+ @args: Array[untyped]
147
+
148
+ def initialize: (*untyped args) -> void
149
+
150
+ def each: () { (untyped) -> void } -> untyped
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,28 @@
1
+ module RBS
2
+ module UnitTest
3
+ module Spy
4
+ def self.wrap: [T] (untyped object, Symbol method_name) -> WrapSpy[T]
5
+ | [T, S] (untyped object, Symbol method_name) { (WrapSpy[T], T) -> S } -> S
6
+
7
+ class WrapSpy[T]
8
+ attr_accessor callback: ^(Test::CallTrace) -> void
9
+
10
+ attr_reader object: T
11
+
12
+ attr_reader method_name: Symbol
13
+
14
+ def initialize: (object: T, method_name: Symbol) -> void
15
+
16
+ def wrapped_object: () -> untyped
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ class Proc
23
+ def ruby2_keywords: () -> self
24
+ end
25
+
26
+ class Module
27
+ def ruby2_keywords: (*Symbol) -> void
28
+ end
@@ -0,0 +1,194 @@
1
+ module RBS
2
+ module UnitTest
3
+ # TypeAssertions provides assertions to test RBS type definitions in unit test
4
+ #
5
+ # ```ruby
6
+ # class FooInstanceTest < Test::Unit::TestCase
7
+ # include RBS::UnitTest::TypeAssertions
8
+ #
9
+ # testing "::Foo"
10
+ #
11
+ # def test_foo
12
+ # assert_send_type(
13
+ # "(String) -> Integer",
14
+ # Foo.new, :foo, "hello"
15
+ # )
16
+ # end
17
+ # end
18
+ # ```
19
+ #
20
+ # The module provides four assertions:
21
+ #
22
+ # * `assert_send_type` to confirm if a method call has the expected method type
23
+ # * `refute_send_type` to confirm if a method call doesn't have the method type
24
+ # * `assert_const_type` to confirm if a constant has an expected type
25
+ # * `assert_type` to confirm a Ruby value has a RBS type
26
+ #
27
+ # See `.testing` and `.library` methods to set up RBS type testing.
28
+ #
29
+ module TypeAssertions : _BaseAssertions
30
+ type target_type = Types::ClassInstance | Types::ClassSingleton
31
+
32
+ interface _BaseAssertions
33
+ def assert: (untyped, ?String?) -> void
34
+
35
+ def refute: (untyped, ?String?) -> void
36
+
37
+ def assert_empty: (untyped, ?String?) -> void
38
+
39
+ def assert_operator: (untyped, Symbol, *untyped) -> void
40
+
41
+ def notify: (untyped) -> void
42
+
43
+ def assert_predicate: (untyped, Symbol, ?String?) -> void
44
+
45
+ def refute_predicate: (untyped, Symbol, ?String?) -> void
46
+ end
47
+
48
+ module ClassMethods
49
+ attr_reader target: [target_type, Definition]?
50
+
51
+ @libs: Array[String]
52
+
53
+ @env: Environment?
54
+
55
+ @@env_cache: Hash[Array[String], Environment]
56
+
57
+ # `testing` is to tell the framework which class is being tested
58
+ #
59
+ # ```ruby
60
+ # testing "::String"
61
+ # testing "::Array[Integer]"
62
+ #
63
+ # testing "singleton(::Integer)"
64
+ # ```
65
+ #
66
+ def testing: (String | target_type) -> void
67
+
68
+ # `library` is to load RBS type definition of dependencies
69
+ #
70
+ # The test or implementation already `require` dependencies, but the RBS type definition of the dependencies are also required for testing.
71
+ #
72
+ # ```ruby
73
+ # library "pathname", "securerandom"
74
+ # ```
75
+ #
76
+ def library: (*String) -> void
77
+
78
+ def env: () -> Environment
79
+
80
+ @builder: DefinitionBuilder
81
+
82
+ def builder: () -> DefinitionBuilder
83
+ end
84
+
85
+ def self.included: (Module) -> void
86
+
87
+ def env: () -> Environment
88
+
89
+ def builder: () -> DefinitionBuilder
90
+
91
+ @targets: Array[[target_type, Definition]]
92
+
93
+ def targets: () -> Array[[target_type, Definition]]
94
+
95
+ def target: () -> [target_type, Definition]
96
+
97
+ def testing: (String | target_type) ?{ () -> void } -> void
98
+
99
+ # The class object that is associated to the `instance` type of the testing type
100
+ #
101
+ def instance_class: () -> Class
102
+
103
+ # The singleton class object that is associated to the `class` type of the testing type
104
+ #
105
+ def class_class: () -> Class
106
+
107
+ def method_types: (Symbol) -> Array[MethodType]
108
+
109
+ def allows_error: (*Exception) { () -> void } -> void
110
+
111
+ # Calls a method `method_name` and validates if it's compatible with RBS type definition
112
+ #
113
+ # 1. It calls `method_name` with `receiver` passing `args` and given block,
114
+ # 2. Validates if it's compatible with given `method_type`, and
115
+ # 3. Validates if it's also compatible with one of the overloads defined in RBS type definition
116
+ #
117
+ # ```ruby
118
+ # assert_send_type(
119
+ # "(::Integer) -> ::Integer",
120
+ # [], :sum, 8
121
+ # )
122
+ # ```
123
+ #
124
+ # To test methods that takes a block, pass a block to `assert_send_type`.
125
+ # We recommend using `&proc { ... }` syntax for textual representation and prevent from using `break` from the block.
126
+ #
127
+ # ```ruby
128
+ # assert_send_type(
129
+ # "() { () -> void } -> void",
130
+ # self, :loop, &proc { break_from_block }
131
+ # )
132
+ # ```
133
+ #
134
+ # Exiting from the block using `break` and `return` skips assertions.
135
+ # Use `break_from_block` instead.
136
+ #
137
+ # `method_type` must be _simple_.
138
+ # It raises an exception if it's not _simple_.
139
+ # When you really need _non-simple_ `method_type`, wrap the calls inside `allow_non_simple_method_type`.
140
+ # See `docs/stdlib.md` for the details.
141
+ #
142
+ def assert_send_type: (String | MethodType method_type, untyped receiver, Symbol method_name, *untyped args) ?{ () -> untyped } -> void
143
+
144
+ # Calls a method `method_name` and validates if it's **not** compatible with RBS type definition
145
+ #
146
+ # 1. It calls `method_name` with `receiver` passing `args` and given block,
147
+ # 2. Validates if it's compatible with given `method_type`, and
148
+ # 3. Validates if it's not compatible with **none** of the overloads defined in RBS type definition
149
+ #
150
+ # See `assert_send_type` for the details.
151
+ #
152
+ def refute_send_type: (String | MethodType method_type, untyped receiver, Symbol method_name, *untyped args) ?{ () -> untyped } -> void
153
+
154
+ # Asserts if the constant `constant_name` has `constant_type`, and the RBS definition has compatible type
155
+ #
156
+ # ```ruby
157
+ # assert_const_type("Array[String]", "::Foo::Bar")
158
+ # ```
159
+ #
160
+ # The assertion above succeeds if `::Foo::Bar` is `["foo"]` and RBS contains `::Foo::Bar: [untyped]`.
161
+ # It fails if `::Foo::Bar` is `[2]`, or the RBS definition is `::Foo::Bar: String`.
162
+ #
163
+ def assert_const_type: (String | Types::t constant_type, String constant_name) -> void
164
+
165
+ # Asserts if given `value` has a type of `value_type`
166
+ #
167
+ def assert_type: (String | Types::t value_type, untyped value) -> void
168
+
169
+ # Allow non _simple-type_ method types given to `assert_send_type` and `refute_send_type`
170
+ #
171
+ # ```ruby
172
+ # allow_non_simple_method_type do
173
+ # assert_send_type("() -> self", ...)
174
+ # end
175
+ # ```
176
+ #
177
+ def allow_non_simple_method_type: () { () -> void } -> void
178
+
179
+ @allows_non_simple_method_type: boolish
180
+
181
+ def validate_simple_method_type: (MethodType) -> void
182
+
183
+ # Break from `assert_send_type` or `refute_send_type`
184
+ #
185
+ def break_from_block: (?untyped value) -> void
186
+
187
+ @break_tag: untyped
188
+
189
+ def send_setup: [T] (String | RBS::MethodType method_type, untyped receiver, Symbol method_name, Array[untyped] args, Proc?) { (RBS::MethodType, Test::CallTrace, untyped, Exception?) -> T } -> T
190
+
191
+ def pass: (?String? message) -> void
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,136 @@
1
+ module RBS
2
+ module UnitTest
3
+ # WithAliases module provides `with_***` methods that helps writing tests which passes convertible objects
4
+ #
5
+ # ```ruby
6
+ # include WithAliases
7
+ #
8
+ # with_int do |i|
9
+ # # Yields Integer and RBS::UnitTest::Convertibles::ToInt
10
+ # end
11
+ #
12
+ # with_string.and_nil do |s|
13
+ # # Yields String, RBS::UnitTest::Convertibles::ToStr, and nil
14
+ # end
15
+ # ```
16
+ #
17
+ module WithAliases
18
+ include Convertibles
19
+
20
+ class WithEnum[T]
21
+ @enum: _Each[T]
22
+
23
+ include Enumerable[T]
24
+
25
+ def initialize: (_Each[T] enum) -> void
26
+
27
+ def each: () { (T) -> void } -> void
28
+
29
+ # Yield `nil` in addition to original `enum` elements
30
+ #
31
+ # ```ruby
32
+ # e = WithEnum.new([1, 2])
33
+ # e.and_nil do |i|
34
+ # pp i # => 1, 2, and nil
35
+ # end
36
+ # ```
37
+ #
38
+ def and_nil: () { (T?) -> void } -> void
39
+ | () -> WithEnum[T?]
40
+
41
+ # Skip yielding objects in `cases`
42
+ #
43
+ # ```ruby
44
+ # e = WithEnum.new([1, 2, 3])
45
+ # e.but(2) do |i|
46
+ # pp i # => 1 and 3
47
+ # end
48
+ # ```
49
+ #
50
+ def but: (*T cases) { (T) -> void } -> void
51
+ | (*T cases) -> WithEnum[T]
52
+
53
+ # Yield objects in `args` in addition to original `enum` elements
54
+ #
55
+ # ```ruby
56
+ # e = WithEnum.new([1, 2])
57
+ # e.and(3) do |i|
58
+ # pp i # => 1, 2, and 3
59
+ # end
60
+ # ```
61
+ #
62
+ def and: [S] (*S args) { (T | S) -> void } -> void
63
+ | [S] (*S args) -> WithEnum[T | S]
64
+ end
65
+
66
+ # Yields `args` objects
67
+ #
68
+ def with: (*untyped args) -> void
69
+ | (*untyped args) { (untyped) -> void } -> void
70
+
71
+ # Yields `::int` objects
72
+ #
73
+ def with_int: (?Integer value) { (int) -> void } -> void
74
+ | (?Integer value) -> WithEnum[int]
75
+
76
+ # Yields `::float` objects
77
+ #
78
+ def with_float: (?Float value) { (float) -> void } -> void
79
+ | (?Float value) -> WithEnum[float]
80
+
81
+ # Yields `::string` objects
82
+ #
83
+ def with_string: (?String value) { (string) -> void } -> void
84
+ | (?String value) -> WithEnum[string]
85
+
86
+ # Yields `::array` objects
87
+ #
88
+ def with_array: [T] (*T elements) { (array[T]) -> void } -> void
89
+ | [T] (*T elements) -> WithEnum[array[T]]
90
+
91
+ # Yields `::hash` objects
92
+ #
93
+ def with_hash: [K, V] (?Hash[K, V] hash) { (hash[K, V]) -> void } -> void
94
+ | [K, V] (?Hash[K, V] hash) -> WithEnum[hash[K, V]]
95
+
96
+ # Yields `::io` objects
97
+ #
98
+ def with_io: (?untyped io) { (io) -> void } -> void
99
+ | (?untyped io) -> WithEnum[io]
100
+
101
+ # Yields `::path` objects
102
+ #
103
+ def with_path: (?String path) { (path) -> void } -> void
104
+ | (?String path) -> WithEnum[path]
105
+
106
+ # Yields `::encoding` objects
107
+ #
108
+ def with_encoding: (?untyped encoding) { (encoding) -> void } -> void
109
+ | (?untyped encoding) -> WithEnum[encoding]
110
+
111
+ # Yields `::interned` objects
112
+ #
113
+ def with_interned: (?Symbol value) { (interned) -> void } -> void
114
+ | (?Symbol value) -> WithEnum[interned]
115
+
116
+ # Yields `::bool` objects
117
+ #
118
+ def with_bool: () { (bool) -> void } -> void
119
+ | () -> WithEnum[bool]
120
+
121
+ # Yields `::boolish` objects
122
+ #
123
+ def with_boolish: () { (boolish) -> void } -> void
124
+ | () -> WithEnum[boolish]
125
+
126
+ # Yields `::untyped` objects
127
+ #
128
+ def with_untyped: () { (untyped) -> void } -> void
129
+ | () -> WithEnum[untyped]
130
+
131
+ # Yields `::range` objects
132
+ #
133
+ def with_range: (WithEnum[untyped] start, WithEnum[untyped] stop, ?bool exclude_end) { (range[untyped]) -> void } -> void
134
+ end
135
+ end
136
+ end