blankity 0.8.0 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ac387131a2ec24c66cc4c22c214addbf73b0ab121350a39d4db6556fa78113c
4
- data.tar.gz: 35a28db8ef6f0d040683c16e241897cc96ab4d0f0e754e6399cefd5d384a775f
3
+ metadata.gz: 82b868a367489a12b73f469c8bda91b12bd4342ea50eca5014594dc852b9e77a
4
+ data.tar.gz: 9bc3240a45986f4781d0c69bb40614555e5be376e25ef47813f5063bea024bde
5
5
  SHA512:
6
- metadata.gz: 9d189e2a9a0b63d7cd30636d7f0a645341fe8cf5fca106b2c1569f54ab15ef93984884014b69aa6bad0542669cf7c6eb9627a3d4d75a10d9bfa6b243a14179a1
7
- data.tar.gz: 815454f7b361da955246a3f7119f8634b0e422563c3a41e5da22ae08c713c910dd7c017ee1879ce33070e4bb144957743da4293aedc8a8601dd3610f0e63c937
6
+ metadata.gz: b322727491e488bd3c72a52b2018d5898f0e2a53049f745738bb4c22ed71647184b5b235492a17fbc103c2e5e69c72b6d1aa8035c0f0ae4dc921f36b22bfc0e7
7
+ data.tar.gz: 424882212731398452338d31e67a68d8b3832ffb8ae0bb3b924ee14290182227fe1aa1722c1d9c0844fd15f23a8328e10b67dd2907f50d0b04dab9428abb3e8b
data/README.md CHANGED
@@ -1,38 +1,86 @@
1
1
  # Blankity
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/blankity`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Blankity is a gem that provides "blank objects," which define minimal methods.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
7
  Install the gem and add to the application's Gemfile by executing:
12
-
13
8
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
9
+ bundle add blankity
15
10
  ```
16
11
 
17
12
  If bundler is not being used to manage dependencies, install the gem by executing:
18
-
19
13
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+ gem install blankity
21
15
  ```
22
16
 
23
17
  ## Usage
24
18
 
25
- TODO: Write usage instructions here
19
+ The `Blankity::Blank` class `undef`s all methods (other than `__send__` and `__id__`) from `BasicObject`:
20
+ ```ruby
21
+ # No methods are defined
22
+ blank = Blankity::Blank.new
23
+ p defined?(blank.==) #=> nil
24
+ p defined?(blank.inspect) #=> nil
25
+
26
+ # Include specific `Object` methods:
27
+ blank = Blankity::Blank.new(methods: [:==])
28
+ p blank == blank #=> true
29
+
30
+ # Also supports blocks, which are `instance_exec`ed
31
+ p Blankity::Blank.new { def inspect = "hi" } #=> "hi"
32
+ ```
33
+
34
+ Also supplied are `Blankity::ToXXX` classes, which just define the conversion methods that are used throughout Ruby's stdlib:
35
+ ```ruby
36
+ # String#* calls `.to_int` on its argument:
37
+ p 'a' * Blankity::ToInt.new(3) #=> "aaa"
38
+
39
+ # File.exist? calls `.to_path` on its argument:
40
+ p File.exist? Blankity::ToPath.new('/tmp/foo') #=> false
41
+
42
+ # Array#[] accepts custom ranges:
43
+ p %w[a b c d][Blankity::Range.new(1, 3)] #=> ["b", "c", "d"]
44
+
45
+ ```
46
+
47
+ As a convenience, `Blankity::To` defines these conversion methods:
48
+ ```ruby
49
+ puts 'hello' + Blankity::To.str(' world')
50
+ #=> hello world
51
+
52
+ puts 'hello'.gsub(/[eo]/, Blankity::To.hash('e' => 'E', 'o' => 'O'))
53
+ #=> hEllO
54
+ ```
55
+
56
+ The `Blankity::To` module is also a mixin!
57
+ ```ruby
58
+ extend Blankity::To
59
+
60
+ puts 'hello' + str(' world')
61
+ exit int(0)
62
+
63
+ # Let's get crazy!
64
+ system(
65
+ hash(
66
+ str('HELLO', hash: true) => str('WORLD')
67
+ ),
68
+ ary(str('sh'), str('-sh')),
69
+ str('-c'),
70
+ str('echo $0 $HELLO $PWD'),
71
+ chdir: path('/'),
72
+ )
73
+ ```
26
74
 
27
75
  ## Development
28
76
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+ Run tests via `rake test` and `steep check`.
30
78
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+ Before pushing new versions, make sure to run `bundle exec rbs-inline --output lib` to generate new rbs signatures, and to update the `version.rb` file.
32
80
 
33
81
  ## Contributing
34
82
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/blankity.
83
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sampersand/blankity.
36
84
 
37
85
  ## License
38
86
 
@@ -4,7 +4,7 @@
4
4
  module Blankity
5
5
  # An "emptier" class than {BasicObject}, which +undef+ines nearly all instance methods.
6
6
  #
7
- # Not _all_ methods are undefined (see {AboslutelyBlank} for a class which does):
7
+ # Not _all_ methods are undefined (see {Top} for a class which does):
8
8
  #
9
9
  # - Methods which match +/\\A__.*__\\z/+ are not removed. Traditionally, these methods are expected
10
10
  # to always be present (and +undef+ing them warns you!). Ruby has two of these: +__send__+
@@ -2,55 +2,66 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
- # Superclass of +ToXXX+ types
6
- #
7
- # @rbs generic T -- type of @__value__
8
- class BlankValue < Blank
9
- # @rbs @__value__: T
5
+ # A Class which only defines +#to_i+; it implements RBS's +_ToI+ interface.
6
+ class ToI < Blank
7
+ # @rbs @__value__: Integer
10
8
 
11
- # Creates a new {BlankValue}, and defining singleton methods depending on the parameters
12
- #
13
- # @param value [T] the backing value for this class
14
- # @param methods [Array[interned]] a list of {OBject} methods to define on +self+.
15
- # @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
16
- # type can be used as a key in +Hash+es
17
- # @yield [] if a block is given, runs it via +instance_exec+.
9
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
18
10
  #
19
- # @rbs (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
11
+ # @rbs (Integer, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
20
12
  def initialize(value, ...)
21
13
  @__value__ = value
22
14
  super(...)
23
15
  end
24
- end
25
16
 
26
- # A Class which exclusively defines +#to_i+; it implements RBS's +_ToI+ interface.
27
- #
28
- # @rbs inherits BlankValue[Integer]
29
- class ToI < BlankValue
30
17
  #: () -> Integer
31
18
  def to_i = @__value__
32
19
  end
33
20
 
34
21
  # A Class which exclusively defines +#to_int+; it implements RBS's +_ToInt+ interface.
35
- #
36
- # @rbs inherits BlankValue[Integer]
37
- class ToInt < BlankValue
22
+ class ToInt < Blank
23
+ # @rbs @__value__: Integer
24
+
25
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
26
+ #
27
+ # @rbs (Integer, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
28
+ def initialize(value, ...)
29
+ @__value__ = value
30
+ super(...)
31
+ end
32
+
38
33
  #: () -> Integer
39
34
  def to_int = @__value__
40
35
  end
41
36
 
42
37
  # A Class which exclusively defines +#to_s+; it implements RBS's +_ToS+ interface.
43
- #
44
- # @rbs inherits BlankValue[String]
45
- class ToS < BlankValue
38
+ class ToS < Blank
39
+ # @rbs @__value__: String
40
+
41
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
42
+ #
43
+ # @rbs (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
44
+ def initialize(value, ...)
45
+ @__value__ = value
46
+ super(...)
47
+ end
48
+
46
49
  #: () -> String
47
50
  def to_s = @__value__
48
51
  end
49
52
 
50
53
  # A Class which exclusively defines +#to_str+; it implements RBS's +_ToStr+ interface.
51
- #
52
- # @rbs inherits BlankValue[String]
53
- class ToStr < BlankValue
54
+ class ToStr < Blank
55
+ # @rbs @__value__: String
56
+
57
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
58
+ #
59
+ # @rbs (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
60
+ def initialize(value, ...)
61
+ @__value__ = value
62
+ super(...)
63
+ end
64
+
54
65
  #: () -> String
55
66
  def to_str = @__value__
56
67
  end
@@ -58,8 +69,17 @@ module Blankity
58
69
  # A Class which exclusively defines +#to_a+; it implements RBS's +_ToA[T]+ interface.
59
70
  #
60
71
  # @rbs generic unchecked out T -- Type of elements
61
- # @rbs inherits BlankValue[Array[T]]
62
- class ToA < BlankValue
72
+ class ToA < Blank
73
+ # @rbs @__value__: Array[T]
74
+
75
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
76
+ #
77
+ # @rbs (Array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
78
+ def initialize(value, ...)
79
+ @__value__ = value
80
+ super(...)
81
+ end
82
+
63
83
  #: () -> Array[T]
64
84
  def to_a = @__value__
65
85
  end
@@ -67,8 +87,17 @@ module Blankity
67
87
  # A Class which exclusively defines +#to_ary+; it implements RBS's +_ToAry[T]+ interface.
68
88
  #
69
89
  # @rbs generic unchecked out T -- Type of elements
70
- # @rbs inherits BlankValue[Array[T]]
71
- class ToAry < BlankValue
90
+ class ToAry < Blank
91
+ # @rbs @__value__: Array[T]
92
+
93
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
94
+ #
95
+ # @rbs (Array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
96
+ def initialize(value, ...)
97
+ @__value__ = value
98
+ super(...)
99
+ end
100
+
72
101
  #: () -> Array[T]
73
102
  def to_ary = @__value__
74
103
  end
@@ -77,8 +106,17 @@ module Blankity
77
106
  #
78
107
  # @rbs generic unchecked out K -- Type of Key
79
108
  # @rbs generic unchecked out V -- Type of Value
80
- # @rbs inherits BlankValue[Hash[K, V]]
81
- class ToH < BlankValue
109
+ class ToH < Blank
110
+ # @rbs @__value__: Hash[K, V]
111
+
112
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
113
+ #
114
+ # @rbs (Hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
115
+ def initialize(value, ...)
116
+ @__value__ = value
117
+ super(...)
118
+ end
119
+
82
120
  #: () -> Hash[K, V]
83
121
  def to_h = @__value__
84
122
  end
@@ -87,72 +125,145 @@ module Blankity
87
125
  #
88
126
  # @rbs generic unchecked out K -- Type of Key
89
127
  # @rbs generic unchecked out V -- Type of Value
90
- # @rbs inherits BlankValue[Hash[K, V]]
91
- class ToHash < BlankValue
128
+ class ToHash < Blank
129
+ # @rbs @__value__: Hash[K, V]
130
+
131
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
132
+ #
133
+ # @rbs (Hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
134
+ def initialize(value, ...)
135
+ @__value__ = value
136
+ super(...)
137
+ end
138
+
92
139
  #: () -> Hash[K, V]
93
140
  def to_hash = @__value__
94
141
  end
95
142
 
96
143
  # A Class which exclusively defines +#to_sym+; it implements RBS's +_ToSym+ interface.
97
- #
98
- # @rbs inherits BlankValue[Symbol]
99
- class ToSym < BlankValue
144
+ class ToSym < Blank
145
+ # @rbs @__value__: Symbol
146
+
147
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
148
+ #
149
+ # @rbs (Symbol, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
150
+ def initialize(value, ...)
151
+ @__value__ = value
152
+ super(...)
153
+ end
154
+
100
155
  #: () -> Symbol
101
156
  def to_sym = @__value__
102
157
  end
103
158
 
104
159
  # A Class which exclusively defines +#to_r+; it implements RBS's +_ToR+ interface.
105
- #
106
- # @rbs inherits BlankValue[Rational]
107
- class ToR < BlankValue
160
+ class ToR < Blank
161
+ # @rbs @__value__: Rational
162
+
163
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
164
+ #
165
+ # @rbs (Rational, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
166
+ def initialize(value, ...)
167
+ @__value__ = value
168
+ super(...)
169
+ end
170
+
108
171
  #: () -> Rational
109
172
  def to_r = @__value__
110
173
  end
111
174
 
112
175
  # A Class which exclusively defines +#to_c+; it implements RBS's +_ToC+ interface.
113
- #
114
- # @rbs inherits BlankValue[Complex]
115
- class ToC < BlankValue
176
+ class ToC < Blank
177
+ # @rbs @__value__: Complex
178
+
179
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
180
+ #
181
+ # @rbs (Complex, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
182
+ def initialize(value, ...)
183
+ @__value__ = value
184
+ super(...)
185
+ end
186
+
116
187
  #: () -> Complex
117
- def to_C = @__value__
188
+ def to_c = @__value__
118
189
  end
119
190
 
120
191
  # A Class which exclusively defines +#to_f+; it implements RBS's +_ToF+ interface.
121
- #
122
- # @rbs inherits BlankValue[Float]
123
- class ToF < BlankValue
192
+ class ToF < Blank
193
+ # @rbs @__value__: Float
194
+
195
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
196
+ #
197
+ # @rbs (Float, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
198
+ def initialize(value, ...)
199
+ @__value__ = value
200
+ super(...)
201
+ end
202
+
124
203
  #: () -> Float
125
204
  def to_f = @__value__
126
205
  end
127
206
 
128
207
  # A Class which exclusively defines +#to_regexp+; it implements RBS's +Regexp::_ToRegexp+ interface.
129
- #
130
- # @rbs inherits BlankValue[Regexp]
131
- class ToRegexp < BlankValue
208
+ class ToRegexp < Blank
209
+ # @rbs @__value__: Regexp
210
+
211
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
212
+ #
213
+ # @rbs (Regexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
214
+ def initialize(value, ...)
215
+ @__value__ = value
216
+ super(...)
217
+ end
218
+
132
219
  #: () -> Regexp
133
220
  def to_regexp = @__value__
134
221
  end
135
222
 
136
223
  # A Class which exclusively defines +#to_path+; it implements RBS's +_ToPath+ interface.
137
- #
138
- # @rbs inherits BlankValue[String]
139
- class ToPath < BlankValue
224
+ class ToPath < Blank
225
+ # @rbs @__value__: String
226
+
227
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
228
+ #
229
+ # @rbs (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
230
+ def initialize(value, ...)
231
+ @__value__ = value
232
+ super(...)
233
+ end
234
+
140
235
  #: () -> String
141
236
  def to_path = @__value__
142
237
  end
143
238
 
144
239
  # A Class which exclusively defines +#to_io+; it implements RBS's +_ToIO+ interface.
145
- #
146
- # @rbs inherits BlankValue[IO]
147
- class ToIO < BlankValue
240
+ class ToIO < Blank
241
+ # @rbs @__value__: IO
242
+
243
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
244
+ #
245
+ # @rbs (IO, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
246
+ def initialize(value, ...)
247
+ @__value__ = value
248
+ super(...)
249
+ end
250
+
148
251
  #: () -> IO
149
252
  def to_io = @__value__
150
253
  end
151
254
 
152
255
  # A Class which exclusively defines +#to_proc+; it implements RBS's +_ToProc+ interface.
153
- #
154
- # @rbs inherits BlankValue[Proc]
155
- class ToProc < BlankValue
256
+ class ToProc < Blank
257
+ # @rbs @__value__: Proc
258
+
259
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
260
+ #
261
+ # @rbs (Proc, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
262
+ def initialize(value, ...)
263
+ @__value__ = value
264
+ super(...)
265
+ end
266
+
156
267
  #: () -> Proc
157
268
  def to_proc = @__value__
158
269
  end
@@ -166,6 +277,8 @@ module Blankity
166
277
  # @rbs @end: T?
167
278
  # @rbs @exclude_end: bool
168
279
 
280
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
281
+ #
169
282
  # @rbs (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
170
283
  def initialize(begin_, end_, exclude_end = false, ...)
171
284
  @__begin__ = begin_
data/lib/blankity/to.rb CHANGED
@@ -5,119 +5,123 @@ module Blankity
5
5
  module To
6
6
  module_function
7
7
 
8
+ # Convenience method to make {ToI}s from +value.to_i+
9
+ #
8
10
  # @rbs (_ToI, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToI] -> void } -> ToI
9
11
  def i(value, ...) = ToI.new(value.to_i, ...)
10
12
 
13
+ # Convenience method to make {ToInt}s from +value.to_int+
14
+ #
11
15
  # @rbs (int, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToInt] -> void } -> ToInt
12
16
  def int(value, ...) = ToInt.new(value.to_int, ...)
13
17
 
18
+ # Convenience method to make {ToS}s from +value.to_s+
19
+ #
14
20
  # @rbs (_ToS, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToS] -> void } -> ToS
15
21
  def s(value, ...) = ToS.new(value.to_s, ...)
16
22
 
23
+ # Convenience method to make {ToStr}s from +value.to_str+
24
+ #
17
25
  # @rbs (string, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToStr] -> void } -> ToStr
18
26
  def str(value, ...) = ToStr.new(value.to_str, ...)
19
27
 
20
- # Create a type which _only_ responds to `.to_a`. See `to_helper` for details.
21
- #
22
- # This supports `a(1, 2, 3)` as a convenient shorthand for `a([1, 2, 3])`. To
23
- # create a `.to_a` that returns an array containing just an array, just use `a([array])`.
28
+ # Convenience method to make {ToA}s from +elements+
24
29
  #
25
- # @rbs [T] (_ToA[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
26
- # | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
27
- def a(*elements, **, &)
28
- if elements.length == 1 && defined?(elements[0].to_a)
29
- elements = (__any__ = elements[0]).to_a
30
- end
31
-
32
- ToA.new(elements, **, &)
33
- end
30
+ # @rbs [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
31
+ def a(*elements, **, &) = ToA.new(elements, **, &)
34
32
 
35
- # Create a type which _only_ responds to `.to_ary`. See `to_helper` for details.
36
- #
37
- # This supports `ary(1, 2, 3)` as a convenient shorthand for `ary([1, 2, 3])`. To
38
- # create a `.to_ary` that returns an array containing just an array, use `ary([array])`.
33
+ # Convenience method to make {ToAry}s from +elements+
39
34
  #
40
- # @rbs [T] (array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
41
- # | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
42
- def ary(*elements, **, &)
43
- if elements.length == 1 && defined?(elements[0].to_ary)
44
- elements = (__any__ = elements[0]).to_ary
45
- end
46
-
47
- ToAry.new(elements, **, &)
48
- end
35
+ # @rbs [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
36
+ def ary(*elements, **, &) = ToAry.new(elements, **, &)
49
37
 
50
- # Create a type which _only_ responds to `.to_h`. See `to_helper` for details.
38
+ # Convenience method to make {ToH}s from +hash+
51
39
  #
52
- # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
53
- # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
54
- # to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
40
+ # This supports passing in key/values directly via +Blankity::To.h('a' => 'b')+ as a convenient
41
+ # shorthand, but you can't then pass keyword arguments to {ToH}'s constructor. To do so, instead
42
+ # pass in a Hash as a positional argument (e.g. +Blankity::To.h({ 'a' => 'b' }, ...)+)
55
43
  #
56
44
  # @rbs [K, V] (_ToH[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
57
45
  # | [K, V] (**V) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
58
- def h(hash = nohash=true, **, &)
59
- if nohash
60
- ToH.new({**}, &)
61
- else
46
+ def h(hash = nil, **, &)
47
+ if hash
62
48
  ToH.new(hash.to_h, **, &)
49
+ else
50
+ ToH.new({**}, &)
63
51
  end
64
52
  end
65
53
 
66
- # Create a type which _only_ responds to `.to_hash`. See `to_helper` for details.
54
+ # Convenience method to make {ToHash}s from +hash+
67
55
  #
68
- # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
69
- # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
70
- # to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
56
+ # This supports passing in key/values directly via +Blankity::To.hash('a' => 'b')+ as a convenient
57
+ # shorthand, but you can't then pass keyword arguments to {ToHash}'s constructor. To do so, instead
58
+ # pass in a Hash as a positional argument (e.g. +Blankity::To.hash({ 'a' => 'b' }, ...)+)
71
59
  #
72
60
  # @rbs [K, V] (hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
73
61
  # | [K, V] (**V) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
74
- def hash(hash = nohash=true, **, &)
75
- if nohash
76
- ToHash.new({**}, &)
62
+ def hash(hash = nil, **, &)
63
+ if hash
64
+ ToHash.new(hash.to_hash, **, &)
77
65
  else
78
- ToHash.new((__any__ = hash).to_hash, **, &)
66
+ ToHash.new({**}, &)
79
67
  end
80
68
  end
81
69
 
70
+ # Convenience method to make {ToSym}s from +value.to_sym+
71
+ #
82
72
  # @rbs (_ToSym, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToSym] -> void } -> ToSym
83
73
  def sym(value, ...) = ToSym.new(value.to_sym, ...)
84
74
 
75
+ # Convenience method to make {ToR}s from +value.to_r+
76
+ #
85
77
  # @rbs (_ToR, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToR] -> void } -> ToR
86
78
  def r(value, ...) = ToR.new(value.to_r, ...)
87
79
 
80
+ # Convenience method to make {ToC}s from +value.to_c+
81
+ #
88
82
  # @rbs (_ToC, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToC] -> void } -> ToC
89
83
  def c(value, ...) = ToC.new(value.to_c, ...)
90
84
 
85
+ # Convenience method to make {ToF}s from +value.to_f+
86
+ #
91
87
  # @rbs (float, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToF] -> void } -> ToF
92
88
  def f(value, ...) = ToF.new(value.to_f, ...)
93
89
 
90
+ # Convenience method to make {ToRegexp}s from +value.to_regexp+
91
+ #
94
92
  # @rbs (Regexp::_ToRegexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToRegexp] -> void } -> ToRegexp
95
93
  def regexp(value, ...) = ToRegexp.new(value.to_regexp, ...)
96
94
 
95
+ # Convenience method to make {ToPath}s from +value.to_path+, or +Kernel#String(value)+
96
+ # if +value+ doesn't define +#to_path+.
97
+ #
97
98
  # @rbs (path, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToPath] -> void } -> ToPath
98
- def path(value, ...)
99
- ToPath.new(defined?(value.to_path) ? value.to_path : String(value), ...)
100
- end
99
+ def path(value, ...) = ToPath.new(defined?(value.to_path) ? value.to_path : String(value), ...)
101
100
 
101
+ # Convenience method to make {ToIO}s from +value.to_io+
102
+ #
102
103
  # @rbs (io, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToIO] -> void } -> ToIO
103
104
  def io(value, ...) = ToIO.new(value.to_io, ...)
104
105
 
106
+ # Convenience method to make {ToProc}s from the supplied block, or +proc+ if no block is given.
107
+ #
108
+ # This supports passing blocks in directly via +Blankity::To.proc { ... }+ as a convenient
109
+ # shorthand, but then you can't pass a block to {ToProc}'s constructor. To so do, instead pass
110
+ # the block as a positional parameter (eg +Blankity::To.proc(proc { ... }) { ... }+)
111
+ #
105
112
  # @rbs (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
106
- def proc(proc = noproc=true, **, &block)
107
- if noproc
108
- unless block_given?
109
- raise ArgumentError, 'if an explicit proc is omitted, a block must be passed'
110
- end
111
-
112
- ToProc.new(__any__ = block, **)
113
- else
113
+ # | (?methods: Array[interned], ?hash: bool) { (?) -> untyped } -> ToProc
114
+ def proc(proc = nil, **, &block)
115
+ if proc
114
116
  ToProc.new(proc.to_proc, **, &block)
117
+ elsif !block_given?
118
+ raise ArgumentError, 'if an explicit proc is omitted, a block must be passed'
119
+ else
120
+ ToProc.new(__any__ = block, **)
115
121
  end
116
122
  end
117
123
 
118
- # Create a type which _only_ responds to `.begin`, `.end`, and `.exclude_end?`
119
- # (the methods required to be considered a "custom range," eg for `Array#[]`.) See
120
- # `to_helper` for details.
124
+ # Convenience method to make {Range}s from the supplied arguments.
121
125
  #
122
126
  # @rbs [T] (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: Range[T]] -> void } -> Range[T]
123
127
  def range(begin_, end_, exclude_end = false, ...)
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
- VERSION = '0.8.0'
5
+ VERSION = '0.9.0'
6
6
  end
@@ -3,7 +3,7 @@
3
3
  module Blankity
4
4
  # An "emptier" class than {BasicObject}, which +undef+ines nearly all instance methods.
5
5
  #
6
- # Not _all_ methods are undefined (see {AboslutelyBlank} for a class which does):
6
+ # Not _all_ methods are undefined (see {Top} for a class which does):
7
7
  #
8
8
  # - Methods which match +/\\A__.*__\\z/+ are not removed. Traditionally, these methods are expected
9
9
  # to always be present (and +undef+ing them warns you!). Ruby has two of these: +__send__+
@@ -1,52 +1,54 @@
1
1
  # Generated from lib/blankity/classes.rb with RBS::Inline
2
2
 
3
3
  module Blankity
4
- # Superclass of +ToXXX+ types
5
- #
6
- # @rbs generic T -- type of @__value__
7
- class BlankValue[T] < Blank
8
- @__value__: T
4
+ # A Class which only defines +#to_i+; it implements RBS's +_ToI+ interface.
5
+ class ToI < Blank
6
+ @__value__: Integer
9
7
 
10
- # Creates a new {BlankValue}, and defining singleton methods depending on the parameters
11
- #
12
- # @param value [T] the backing value for this class
13
- # @param methods [Array[interned]] a list of {OBject} methods to define on +self+.
14
- # @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
15
- # type can be used as a key in +Hash+es
16
- # @yield [] if a block is given, runs it via +instance_exec+.
8
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
17
9
  #
18
- # @rbs (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
19
- def initialize: (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
20
- end
10
+ # @rbs (Integer, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
11
+ def initialize: (Integer, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
21
12
 
22
- # A Class which exclusively defines +#to_i+; it implements RBS's +_ToI+ interface.
23
- #
24
- # @rbs inherits BlankValue[Integer]
25
- class ToI < BlankValue[Integer]
26
13
  # : () -> Integer
27
14
  def to_i: () -> Integer
28
15
  end
29
16
 
30
17
  # A Class which exclusively defines +#to_int+; it implements RBS's +_ToInt+ interface.
31
- #
32
- # @rbs inherits BlankValue[Integer]
33
- class ToInt < BlankValue[Integer]
18
+ class ToInt < Blank
19
+ @__value__: Integer
20
+
21
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
22
+ #
23
+ # @rbs (Integer, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
24
+ def initialize: (Integer, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
25
+
34
26
  # : () -> Integer
35
27
  def to_int: () -> Integer
36
28
  end
37
29
 
38
30
  # A Class which exclusively defines +#to_s+; it implements RBS's +_ToS+ interface.
39
- #
40
- # @rbs inherits BlankValue[String]
41
- class ToS < BlankValue[String]
31
+ class ToS < Blank
32
+ @__value__: String
33
+
34
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
35
+ #
36
+ # @rbs (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
37
+ def initialize: (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
38
+
42
39
  # : () -> String
43
40
  def to_s: () -> String
44
41
  end
45
42
 
46
43
  # A Class which exclusively defines +#to_str+; it implements RBS's +_ToStr+ interface.
47
- #
48
- # @rbs inherits BlankValue[String]
49
- class ToStr < BlankValue[String]
44
+ class ToStr < Blank
45
+ @__value__: String
46
+
47
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
48
+ #
49
+ # @rbs (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
50
+ def initialize: (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
51
+
50
52
  # : () -> String
51
53
  def to_str: () -> String
52
54
  end
@@ -54,8 +56,14 @@ module Blankity
54
56
  # A Class which exclusively defines +#to_a+; it implements RBS's +_ToA[T]+ interface.
55
57
  #
56
58
  # @rbs generic unchecked out T -- Type of elements
57
- # @rbs inherits BlankValue[Array[T]]
58
- class ToA[unchecked out T] < BlankValue[Array[T]]
59
+ class ToA[unchecked out T] < Blank
60
+ @__value__: Array[T]
61
+
62
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
63
+ #
64
+ # @rbs (Array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
65
+ def initialize: (Array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
66
+
59
67
  # : () -> Array[T]
60
68
  def to_a: () -> Array[T]
61
69
  end
@@ -63,8 +71,14 @@ module Blankity
63
71
  # A Class which exclusively defines +#to_ary+; it implements RBS's +_ToAry[T]+ interface.
64
72
  #
65
73
  # @rbs generic unchecked out T -- Type of elements
66
- # @rbs inherits BlankValue[Array[T]]
67
- class ToAry[unchecked out T] < BlankValue[Array[T]]
74
+ class ToAry[unchecked out T] < Blank
75
+ @__value__: Array[T]
76
+
77
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
78
+ #
79
+ # @rbs (Array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
80
+ def initialize: (Array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
81
+
68
82
  # : () -> Array[T]
69
83
  def to_ary: () -> Array[T]
70
84
  end
@@ -73,8 +87,14 @@ module Blankity
73
87
  #
74
88
  # @rbs generic unchecked out K -- Type of Key
75
89
  # @rbs generic unchecked out V -- Type of Value
76
- # @rbs inherits BlankValue[Hash[K, V]]
77
- class ToH[unchecked out K, unchecked out V] < BlankValue[Hash[K, V]]
90
+ class ToH[unchecked out K, unchecked out V] < Blank
91
+ @__value__: Hash[K, V]
92
+
93
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
94
+ #
95
+ # @rbs (Hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
96
+ def initialize: (Hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
97
+
78
98
  # : () -> Hash[K, V]
79
99
  def to_h: () -> Hash[K, V]
80
100
  end
@@ -83,72 +103,118 @@ module Blankity
83
103
  #
84
104
  # @rbs generic unchecked out K -- Type of Key
85
105
  # @rbs generic unchecked out V -- Type of Value
86
- # @rbs inherits BlankValue[Hash[K, V]]
87
- class ToHash[unchecked out K, unchecked out V] < BlankValue[Hash[K, V]]
106
+ class ToHash[unchecked out K, unchecked out V] < Blank
107
+ @__value__: Hash[K, V]
108
+
109
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
110
+ #
111
+ # @rbs (Hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
112
+ def initialize: (Hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
113
+
88
114
  # : () -> Hash[K, V]
89
115
  def to_hash: () -> Hash[K, V]
90
116
  end
91
117
 
92
118
  # A Class which exclusively defines +#to_sym+; it implements RBS's +_ToSym+ interface.
93
- #
94
- # @rbs inherits BlankValue[Symbol]
95
- class ToSym < BlankValue[Symbol]
119
+ class ToSym < Blank
120
+ @__value__: Symbol
121
+
122
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
123
+ #
124
+ # @rbs (Symbol, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
125
+ def initialize: (Symbol, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
126
+
96
127
  # : () -> Symbol
97
128
  def to_sym: () -> Symbol
98
129
  end
99
130
 
100
131
  # A Class which exclusively defines +#to_r+; it implements RBS's +_ToR+ interface.
101
- #
102
- # @rbs inherits BlankValue[Rational]
103
- class ToR < BlankValue[Rational]
132
+ class ToR < Blank
133
+ @__value__: Rational
134
+
135
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
136
+ #
137
+ # @rbs (Rational, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
138
+ def initialize: (Rational, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
139
+
104
140
  # : () -> Rational
105
141
  def to_r: () -> Rational
106
142
  end
107
143
 
108
144
  # A Class which exclusively defines +#to_c+; it implements RBS's +_ToC+ interface.
109
- #
110
- # @rbs inherits BlankValue[Complex]
111
- class ToC < BlankValue[Complex]
145
+ class ToC < Blank
146
+ @__value__: Complex
147
+
148
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
149
+ #
150
+ # @rbs (Complex, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
151
+ def initialize: (Complex, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
152
+
112
153
  # : () -> Complex
113
- def to_C: () -> Complex
154
+ def to_c: () -> Complex
114
155
  end
115
156
 
116
157
  # A Class which exclusively defines +#to_f+; it implements RBS's +_ToF+ interface.
117
- #
118
- # @rbs inherits BlankValue[Float]
119
- class ToF < BlankValue[Float]
158
+ class ToF < Blank
159
+ @__value__: Float
160
+
161
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
162
+ #
163
+ # @rbs (Float, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
164
+ def initialize: (Float, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
165
+
120
166
  # : () -> Float
121
167
  def to_f: () -> Float
122
168
  end
123
169
 
124
170
  # A Class which exclusively defines +#to_regexp+; it implements RBS's +Regexp::_ToRegexp+ interface.
125
- #
126
- # @rbs inherits BlankValue[Regexp]
127
- class ToRegexp < BlankValue[Regexp]
171
+ class ToRegexp < Blank
172
+ @__value__: Regexp
173
+
174
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
175
+ #
176
+ # @rbs (Regexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
177
+ def initialize: (Regexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
178
+
128
179
  # : () -> Regexp
129
180
  def to_regexp: () -> Regexp
130
181
  end
131
182
 
132
183
  # A Class which exclusively defines +#to_path+; it implements RBS's +_ToPath+ interface.
133
- #
134
- # @rbs inherits BlankValue[String]
135
- class ToPath < BlankValue[String]
184
+ class ToPath < Blank
185
+ @__value__: String
186
+
187
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
188
+ #
189
+ # @rbs (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
190
+ def initialize: (String, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
191
+
136
192
  # : () -> String
137
193
  def to_path: () -> String
138
194
  end
139
195
 
140
196
  # A Class which exclusively defines +#to_io+; it implements RBS's +_ToIO+ interface.
141
- #
142
- # @rbs inherits BlankValue[IO]
143
- class ToIO < BlankValue[IO]
197
+ class ToIO < Blank
198
+ @__value__: IO
199
+
200
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
201
+ #
202
+ # @rbs (IO, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
203
+ def initialize: (IO, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
204
+
144
205
  # : () -> IO
145
206
  def to_io: () -> IO
146
207
  end
147
208
 
148
209
  # A Class which exclusively defines +#to_proc+; it implements RBS's +_ToProc+ interface.
149
- #
150
- # @rbs inherits BlankValue[Proc]
151
- class ToProc < BlankValue[Proc]
210
+ class ToProc < Blank
211
+ @__value__: Proc
212
+
213
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
214
+ #
215
+ # @rbs (Proc, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
216
+ def initialize: (Proc, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
217
+
152
218
  # : () -> Proc
153
219
  def to_proc: () -> Proc
154
220
  end
@@ -164,6 +230,8 @@ module Blankity
164
230
 
165
231
  @exclude_end: bool
166
232
 
233
+ # Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
234
+ #
167
235
  # @rbs (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
168
236
  def initialize: (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
169
237
 
@@ -2,87 +2,106 @@
2
2
 
3
3
  module Blankity
4
4
  module To
5
+ # Convenience method to make {ToI}s from +value.to_i+
6
+ #
5
7
  # @rbs (_ToI, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToI] -> void } -> ToI
6
8
  def self?.i: (_ToI, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToI] -> void } -> ToI
7
9
 
10
+ # Convenience method to make {ToInt}s from +value.to_int+
11
+ #
8
12
  # @rbs (int, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToInt] -> void } -> ToInt
9
13
  def self?.int: (int, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToInt] -> void } -> ToInt
10
14
 
15
+ # Convenience method to make {ToS}s from +value.to_s+
16
+ #
11
17
  # @rbs (_ToS, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToS] -> void } -> ToS
12
18
  def self?.s: (_ToS, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToS] -> void } -> ToS
13
19
 
20
+ # Convenience method to make {ToStr}s from +value.to_str+
21
+ #
14
22
  # @rbs (string, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToStr] -> void } -> ToStr
15
23
  def self?.str: (string, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToStr] -> void } -> ToStr
16
24
 
17
- # Create a type which _only_ responds to `.to_a`. See `to_helper` for details.
25
+ # Convenience method to make {ToA}s from +elements+
18
26
  #
19
- # This supports `a(1, 2, 3)` as a convenient shorthand for `a([1, 2, 3])`. To
20
- # create a `.to_a` that returns an array containing just an array, just use `a([array])`.
21
- #
22
- # @rbs [T] (_ToA[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
23
- # | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
24
- def self?.a: [T] (_ToA[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
25
- | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
27
+ # @rbs [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
28
+ def self?.a: [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
26
29
 
27
- # Create a type which _only_ responds to `.to_ary`. See `to_helper` for details.
28
- #
29
- # This supports `ary(1, 2, 3)` as a convenient shorthand for `ary([1, 2, 3])`. To
30
- # create a `.to_ary` that returns an array containing just an array, use `ary([array])`.
30
+ # Convenience method to make {ToAry}s from +elements+
31
31
  #
32
- # @rbs [T] (array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
33
- # | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
34
- def self?.ary: [T] (array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
35
- | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
32
+ # @rbs [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
33
+ def self?.ary: [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
36
34
 
37
- # Create a type which _only_ responds to `.to_h`. See `to_helper` for details.
35
+ # Convenience method to make {ToH}s from +hash+
38
36
  #
39
- # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
40
- # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
41
- # to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
37
+ # This supports passing in key/values directly via +Blankity::To.h('a' => 'b')+ as a convenient
38
+ # shorthand, but you can't then pass keyword arguments to {ToH}'s constructor. To do so, instead
39
+ # pass in a Hash as a positional argument (e.g. +Blankity::To.h({ 'a' => 'b' }, ...)+)
42
40
  #
43
41
  # @rbs [K, V] (_ToH[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
44
42
  # | [K, V] (**V) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
45
43
  def self?.h: [K, V] (_ToH[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
46
44
  | [K, V] (**V) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
47
45
 
48
- # Create a type which _only_ responds to `.to_hash`. See `to_helper` for details.
46
+ # Convenience method to make {ToHash}s from +hash+
49
47
  #
50
- # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
51
- # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
52
- # to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
48
+ # This supports passing in key/values directly via +Blankity::To.hash('a' => 'b')+ as a convenient
49
+ # shorthand, but you can't then pass keyword arguments to {ToHash}'s constructor. To do so, instead
50
+ # pass in a Hash as a positional argument (e.g. +Blankity::To.hash({ 'a' => 'b' }, ...)+)
53
51
  #
54
52
  # @rbs [K, V] (hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
55
53
  # | [K, V] (**V) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
56
54
  def self?.hash: [K, V] (hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
57
55
  | [K, V] (**V) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
58
56
 
57
+ # Convenience method to make {ToSym}s from +value.to_sym+
58
+ #
59
59
  # @rbs (_ToSym, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToSym] -> void } -> ToSym
60
60
  def self?.sym: (_ToSym, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToSym] -> void } -> ToSym
61
61
 
62
+ # Convenience method to make {ToR}s from +value.to_r+
63
+ #
62
64
  # @rbs (_ToR, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToR] -> void } -> ToR
63
65
  def self?.r: (_ToR, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToR] -> void } -> ToR
64
66
 
67
+ # Convenience method to make {ToC}s from +value.to_c+
68
+ #
65
69
  # @rbs (_ToC, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToC] -> void } -> ToC
66
70
  def self?.c: (_ToC, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToC] -> void } -> ToC
67
71
 
72
+ # Convenience method to make {ToF}s from +value.to_f+
73
+ #
68
74
  # @rbs (float, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToF] -> void } -> ToF
69
75
  def self?.f: (float, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToF] -> void } -> ToF
70
76
 
77
+ # Convenience method to make {ToRegexp}s from +value.to_regexp+
78
+ #
71
79
  # @rbs (Regexp::_ToRegexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToRegexp] -> void } -> ToRegexp
72
80
  def self?.regexp: (Regexp::_ToRegexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToRegexp] -> void } -> ToRegexp
73
81
 
82
+ # Convenience method to make {ToPath}s from +value.to_path+, or +Kernel#String(value)+
83
+ # if +value+ doesn't define +#to_path+.
84
+ #
74
85
  # @rbs (path, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToPath] -> void } -> ToPath
75
86
  def self?.path: (path, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToPath] -> void } -> ToPath
76
87
 
88
+ # Convenience method to make {ToIO}s from +value.to_io+
89
+ #
77
90
  # @rbs (io, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToIO] -> void } -> ToIO
78
91
  def self?.io: (io, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToIO] -> void } -> ToIO
79
92
 
93
+ # Convenience method to make {ToProc}s from the supplied block, or +proc+ if no block is given.
94
+ #
95
+ # This supports passing blocks in directly via +Blankity::To.proc { ... }+ as a convenient
96
+ # shorthand, but then you can't pass a block to {ToProc}'s constructor. To so do, instead pass
97
+ # the block as a positional parameter (eg +Blankity::To.proc(proc { ... }) { ... }+)
98
+ #
80
99
  # @rbs (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
100
+ # | (?methods: Array[interned], ?hash: bool) { (?) -> untyped } -> ToProc
81
101
  def self?.proc: (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
102
+ | (?methods: Array[interned], ?hash: bool) { (?) -> untyped } -> ToProc
82
103
 
83
- # Create a type which _only_ responds to `.begin`, `.end`, and `.exclude_end?`
84
- # (the methods required to be considered a "custom range," eg for `Array#[]`.) See
85
- # `to_helper` for details.
104
+ # Convenience method to make {Range}s from the supplied arguments.
86
105
  #
87
106
  # @rbs [T] (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: Range[T]] -> void } -> Range[T]
88
107
  def self?.range: [T] (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: Range[T]] -> void } -> Range[T]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blankity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Westerman
@@ -11,7 +11,7 @@ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: |
13
13
  There's a lot of conversion methods in Ruby: to_s, to_a, to_i, etc. This gem provides types
14
- which *only* respond to these conversion methods, and nothing else.
14
+ which only respond to these conversion methods, and nothing else.
15
15
  email: mail@sampersand.me
16
16
  executables: []
17
17
  extensions: []
@@ -58,5 +58,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  requirements: []
59
59
  rubygems_version: 3.7.0.dev
60
60
  specification_version: 4
61
- summary: Provides "blank" objects which *only* supply conversion methods
61
+ summary: Provides "blank" objects which only supply conversion methods
62
62
  test_files: []