blankity 0.0.2
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/Steepfile +32 -0
- data/lib/blankity/blank.rb +45 -0
- data/lib/blankity/classes.rb +172 -0
- data/lib/blankity/to.rb +151 -0
- data/lib/blankity/version.rb +6 -0
- data/lib/blankity.rb +9 -0
- data/sig/generated/blankity/blank.rbs +19 -0
- data/sig/generated/blankity/tos.rbs +44 -0
- data/sig/generated/blankity/version.rbs +5 -0
- data/sig/generated/blankity.rbs +4 -0
- metadata +53 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6c77ee6b4b3f72c8cfa617313fa1a70f14644c140dae8346fc77e8eeb6a9c7bf
|
|
4
|
+
data.tar.gz: 6d612fe43c3cd9345f27947986a63fc980b2bb95c4f7f003a654fbd8a21c3bd5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e267257370d73d2cd537e2d62da15694574ad00390d4385e487c95d9d4591a6ffd40eb5b14afd93209f222c3afb7356d326bb32988bbaaf9509b43b59ba7bcb2
|
|
7
|
+
data.tar.gz: 56764266af70a160b088875284cfcfa168be5d8d5b1025f2445cafb4c98990affb137564fdaf4176a8a8819c9029acf934c78df176cdcdb03675233e07628402
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SamW
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Blankity
|
|
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.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
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
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
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.
|
|
30
|
+
|
|
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).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/blankity.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/Steepfile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
D = Steep::Diagnostic
|
|
2
|
+
|
|
3
|
+
target :lib do
|
|
4
|
+
signature "sig"
|
|
5
|
+
ignore_signature "sig/test"
|
|
6
|
+
|
|
7
|
+
check "lib" # Directory name
|
|
8
|
+
check "path/to/source.rb" # File name
|
|
9
|
+
check "app/models/**/*.rb" # Glob
|
|
10
|
+
# ignore "lib/templates/*.rb"
|
|
11
|
+
|
|
12
|
+
# library "pathname" # Standard libraries
|
|
13
|
+
# library "strong_json" # Gems
|
|
14
|
+
|
|
15
|
+
# configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
|
|
16
|
+
# configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
|
|
17
|
+
# configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
|
|
18
|
+
# configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
|
|
19
|
+
# configure_code_diagnostics do |hash| # You can setup everything yourself
|
|
20
|
+
# hash[D::Ruby::NoMethod] = :information
|
|
21
|
+
# end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# target :test do
|
|
25
|
+
# unreferenced! # Skip type checking the `lib` code when types in `test` target is changed
|
|
26
|
+
# signature "sig/test" # Put RBS files for tests under `sig/test`
|
|
27
|
+
# check "test" # Type check Ruby scripts under `test`
|
|
28
|
+
|
|
29
|
+
# configure_code_diagnostics(D::Ruby.lenient) # Weak type checking for test code
|
|
30
|
+
|
|
31
|
+
# # library "pathname" # Standard libraries
|
|
32
|
+
# end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Blankity
|
|
5
|
+
# A "blank slate" class which removes _all_ methods (from `BasicObject`) other than the "required"
|
|
6
|
+
# ones of `__send__` and `__id__`.
|
|
7
|
+
class Blank < BasicObject
|
|
8
|
+
# Remove every method except for `__send__` and `__id__`
|
|
9
|
+
instance_methods.each do |name|
|
|
10
|
+
undef_method(name) unless name == :__send__ || name == :__id__
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# A helper method to define some `Kernel`methods on `self`
|
|
14
|
+
def __with_Object_methods__(*methods)
|
|
15
|
+
dsm = ::Object.instance_method(:define_singleton_method).bind(self)
|
|
16
|
+
|
|
17
|
+
methods.each do |method|
|
|
18
|
+
dsm.call(method, ::Object.instance_method(method))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Same as `__with_Object_methods__`, but adds them to subclasses. This shouldn't
|
|
25
|
+
# be called on `Blankity::Blank` directly, as that affects subclasses
|
|
26
|
+
def self.__with_Object_methods__(*methods)
|
|
27
|
+
if ::Blankity::Blank.equal?(self)
|
|
28
|
+
raise ArgumentError, 'Cannot call `__with_Object_methods__` on Blank, as that will affect all blank slates'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
methods.each do |method|
|
|
32
|
+
define_method(method, ::Kernel.instance_method(method))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
self
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Helper method to create a new `Blank` with a block
|
|
39
|
+
def self.blank(&block)
|
|
40
|
+
::Class.new(self, &block).new
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.blank(...) = Blank.blank(...)
|
|
45
|
+
end
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# rbs_inline: enabled
|
|
3
|
+
|
|
4
|
+
module Blankity
|
|
5
|
+
class ValueBase < Blank
|
|
6
|
+
def initialize(value, methods: [], hash: false, &block)
|
|
7
|
+
# If `hash` is supplied, then add `hash` and `eql?` to the list of methods to define
|
|
8
|
+
methods |= %i[hash eql?] if hash
|
|
9
|
+
|
|
10
|
+
@__value__ = value
|
|
11
|
+
|
|
12
|
+
::Blankity.blank do
|
|
13
|
+
# Always define the `to_method`
|
|
14
|
+
define_singleton_method(:inspect) { to_method.to_s }
|
|
15
|
+
define_method(to_method) { value }
|
|
16
|
+
|
|
17
|
+
# For all the `methods` methods, fetch its definition from `value` and use that as the
|
|
18
|
+
# definition
|
|
19
|
+
methods.each do |method|
|
|
20
|
+
define_method(method, &::Kernel.instance_method(:method).bind_call(value, method))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# If a block's given, execute it.
|
|
24
|
+
class_exec(&block) if block
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class ToI < Blank
|
|
29
|
+
#: (Integer) -> void
|
|
30
|
+
def initialize(value) = @__value__ = value
|
|
31
|
+
|
|
32
|
+
#: () -> Integer
|
|
33
|
+
def to_i = @__value__
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class ToInt < Blank
|
|
37
|
+
#: (Integer) -> void
|
|
38
|
+
def initialize(value) = @__value__ = value
|
|
39
|
+
|
|
40
|
+
#: () -> Integer
|
|
41
|
+
def to_int = @__value__
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class ToS < Blank
|
|
45
|
+
#: (String) -> void
|
|
46
|
+
def initialize(value) = @__value__ = value
|
|
47
|
+
|
|
48
|
+
#: () -> String
|
|
49
|
+
def to_s = @__value__
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class ToStr < Blank
|
|
53
|
+
#: (String) -> void
|
|
54
|
+
def initialize(value) = @__value__ = value
|
|
55
|
+
|
|
56
|
+
#: () -> String
|
|
57
|
+
def to_str = @__value__
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @rbs generic unchecked out T -- Type of elements
|
|
61
|
+
class ToA < Blank
|
|
62
|
+
#: (Array[T]) -> void
|
|
63
|
+
def initialize(value) = @__value__ = value
|
|
64
|
+
|
|
65
|
+
#: () -> Array[T]
|
|
66
|
+
def to_a = @__value__
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @rbs generic unchecked out T -- Type of elements
|
|
70
|
+
class ToAry < Blank
|
|
71
|
+
#: (Array[T]) -> void
|
|
72
|
+
def initialize(value) = @__value__ = value
|
|
73
|
+
|
|
74
|
+
#: () -> Array[T]
|
|
75
|
+
def to_ary = @__value__
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @rbs generic unchecked out K -- Type of Key
|
|
79
|
+
# @rbs generic unchecked out V -- Type of Value
|
|
80
|
+
class ToH < Blank
|
|
81
|
+
#: (Hash[K, V]) -> void
|
|
82
|
+
def initialize(value) = @__value__ = value
|
|
83
|
+
|
|
84
|
+
#: () -> Hash[K, V]
|
|
85
|
+
def to_h = @__value__
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# @rbs generic unchecked out K -- Type of Key
|
|
89
|
+
# @rbs generic unchecked out V -- Type of Value
|
|
90
|
+
class ToHash < Blank
|
|
91
|
+
#: (Hash[K, V]) -> void
|
|
92
|
+
def initialize(value) = @__value__ = value
|
|
93
|
+
|
|
94
|
+
#: () -> Hash[K, V]
|
|
95
|
+
def to_hash = @__value__
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class ToSym < Blank
|
|
99
|
+
#: (Symbol) -> void
|
|
100
|
+
def initialize(value) = @__value__ = value
|
|
101
|
+
|
|
102
|
+
#: () -> Symbol
|
|
103
|
+
def to_sym = @__value__
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
class ToR < Blank
|
|
107
|
+
#: (Rational) -> void
|
|
108
|
+
def initialize(value) = @__value__ = value
|
|
109
|
+
|
|
110
|
+
#: () -> Rational
|
|
111
|
+
def to_r = @__value__
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
class ToC < Blank
|
|
115
|
+
#: (Complex) -> void
|
|
116
|
+
def initialize(value) = @__value__ = value
|
|
117
|
+
|
|
118
|
+
#: () -> Complex
|
|
119
|
+
def to_C = @__value__
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
class ToF < Blank
|
|
123
|
+
#: (Float) -> void
|
|
124
|
+
def initialize(value) = @__value__ = value
|
|
125
|
+
|
|
126
|
+
#: () -> Float
|
|
127
|
+
def to_f = @__value__
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
class ToRegexp < Blank
|
|
131
|
+
#: (Regexp) -> void
|
|
132
|
+
def initialize(value) = @__value__ = value
|
|
133
|
+
|
|
134
|
+
#: () -> Regexp
|
|
135
|
+
def to_regexp = @__value__
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
class ToPath < Blank
|
|
139
|
+
#: (String) -> void
|
|
140
|
+
def initialize(value) = @__value__ = value
|
|
141
|
+
|
|
142
|
+
#: () -> String
|
|
143
|
+
def to_path = @__value__
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
class ToIO < Blank
|
|
147
|
+
#: (IO) -> void
|
|
148
|
+
def initialize(value) = @__value__ = value
|
|
149
|
+
|
|
150
|
+
#: () -> IO
|
|
151
|
+
def to_io = @__value__
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# @rbs generic out T -- Type to iterate over
|
|
155
|
+
class Range < Blank
|
|
156
|
+
#: (T?, T?, ?bool) -> void
|
|
157
|
+
def initialize(begin_, end_, exclude_end = false)
|
|
158
|
+
@__begin__ = begin_
|
|
159
|
+
@__end__ = end_
|
|
160
|
+
@__exclude_end__ = exclude_end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
#: () -> T?
|
|
164
|
+
def begin = @__begin__
|
|
165
|
+
|
|
166
|
+
#: () -> T?
|
|
167
|
+
def end = @__end__
|
|
168
|
+
|
|
169
|
+
#: () -> bool
|
|
170
|
+
def exclude_end = @__exclude_end__
|
|
171
|
+
end
|
|
172
|
+
end
|
data/lib/blankity/to.rb
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Blankity
|
|
4
|
+
module To
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
# Helper method to create new `BlankSlate`s. Args:
|
|
8
|
+
# - `to_method`: The method to use, eg `to_i`
|
|
9
|
+
# - `value`: What to return when `to_method` is called
|
|
10
|
+
# - `methods`: Optional list of methods from to define, using `value`'s definition
|
|
11
|
+
# - `hash`: Helper to also add `hash` and `eql?` to `methods`, so it can be used as a hash key
|
|
12
|
+
# - `block`: If provided, a block to also run
|
|
13
|
+
def to_helper(to_method, value, methods: [], hash: false, &block)
|
|
14
|
+
# If `hash` is supplied, then add `hash` and `eql?` to the list of methods to define
|
|
15
|
+
methods |= %i[hash eql?] if hash
|
|
16
|
+
|
|
17
|
+
::Blankity.blank do
|
|
18
|
+
# Always define the `to_method`
|
|
19
|
+
define_singleton_method(:inspect) { to_method.to_s }
|
|
20
|
+
define_method(to_method) { value }
|
|
21
|
+
|
|
22
|
+
# For all the `methods` methods, fetch its definition from `value` and use that as the
|
|
23
|
+
# definition
|
|
24
|
+
methods.each do |method|
|
|
25
|
+
define_method(method, &::Kernel.instance_method(:method).bind_call(value, method))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# If a block's given, execute it.
|
|
29
|
+
class_exec(&block) if block
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Create a type which _only_ responds to `.to_i`. See `to_helper` for details.
|
|
34
|
+
def i(value, ...)
|
|
35
|
+
to_helper(:to_i, value.to_i, ...)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Create a type which _only_ responds to `.to_int`. See `to_helper` for details.
|
|
39
|
+
def int(value, ...)
|
|
40
|
+
to_helper(:to_int, value.to_int, ...)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Create a type which _only_ responds to `.to_s`. See `to_helper` for details.
|
|
44
|
+
def s(value, ...)
|
|
45
|
+
to_helper(:to_s, value.to_s, ...)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Create a type which _only_ responds to `.to_str`. See `to_helper` for details.
|
|
49
|
+
def str(value, ...)
|
|
50
|
+
to_helper(:to_str, value.to_str, ...)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Create a type which _only_ responds to `.to_a`. See `to_helper` for details.
|
|
54
|
+
#
|
|
55
|
+
# This supports `a(1, 2, 3)` as a convenient shorthand for `a([1, 2, 3])`. To
|
|
56
|
+
# create a `.to_a` that returns an array containing just an array, just use `a([array])`.
|
|
57
|
+
def a(*elements, **, &)
|
|
58
|
+
if elements.length == 1
|
|
59
|
+
to_helper(:to_a, Array(elements[0]), **, &)
|
|
60
|
+
else
|
|
61
|
+
to_helper(:to_a, elements, **, &)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Create a type which _only_ responds to `.to_ary`. See `to_helper` for details.
|
|
66
|
+
#
|
|
67
|
+
# This supports `ary(1, 2, 3)` as a convenient shorthand for `ary([1, 2, 3])`. To
|
|
68
|
+
# create a `.to_ary` that returns an array containing just an array, use `ary([array])`.
|
|
69
|
+
def ary(*elements, **, &)
|
|
70
|
+
if elements.length == 1
|
|
71
|
+
to_helper(:to_ary, Array(elements[0]), **, &)
|
|
72
|
+
else
|
|
73
|
+
to_helper(:to_ary, elements, **, &)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Create a type which _only_ responds to `.to_h`. See `to_helper` for details.
|
|
78
|
+
#
|
|
79
|
+
# This supports passing in key/values directly via `h('a' => 'b')` as a convenient
|
|
80
|
+
# shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
|
|
81
|
+
# to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
|
|
82
|
+
def h(hash = nohash=true, **, &)
|
|
83
|
+
if nohash
|
|
84
|
+
to_helper(:to_h, {**}, &)
|
|
85
|
+
else
|
|
86
|
+
to_helper(:to_h, hash.to_h, **, &)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Create a type which _only_ responds to `.to_hash`. See `to_helper` for details.
|
|
91
|
+
#
|
|
92
|
+
# This supports passing in key/values directly via `h('a' => 'b')` as a convenient
|
|
93
|
+
# shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
|
|
94
|
+
# to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
|
|
95
|
+
def hash(hash = nohash=true, **, &)
|
|
96
|
+
if nohash
|
|
97
|
+
to_helper(:to_hash, {**}, &)
|
|
98
|
+
else
|
|
99
|
+
to_helper(:to_hash, hash.to_hash, **, &)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Create a type which _only_ responds to `.to_sym`. See `to_helper` for details.
|
|
104
|
+
def sym(value, ...)
|
|
105
|
+
to_helper(:to_sym, value.to_sym, ...)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Create a type which _only_ responds to `.to_r`. See `to_helper` for details.
|
|
109
|
+
def r(value, ...)
|
|
110
|
+
to_helper(:to_r, value.to_r, ...)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Create a type which _only_ responds to `.to_c`. See `to_helper` for details.
|
|
114
|
+
def c(value, ...)
|
|
115
|
+
to_helper(:to_c, value.to_c, ...)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Create a type which _only_ responds to `.to_f`. See `to_helper` for details.
|
|
119
|
+
def f(value, ...)
|
|
120
|
+
to_helper(:to_f, value.to_f, ...)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Create a type which _only_ responds to `.to_regexp`. See `to_helper` for details.
|
|
124
|
+
def regexp(value, ...)
|
|
125
|
+
to_helper(:to_regexp, value.to_regexp, ...)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Create a type which _only_ responds to `.to_path`. See `to_helper` for details.
|
|
129
|
+
def path(value, ...)
|
|
130
|
+
to_helper(:to_path, defined?(value.to_path) ? value.to_path : String(value), ...)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Create a type which _only_ responds to `.to_io`. See `to_helper` for details.
|
|
134
|
+
def io(value, ...)
|
|
135
|
+
to_helper(:to_io, value.to_io, ...)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Create a type which _only_ responds to `.begin`, `.end`, and `.exclude_end?`
|
|
139
|
+
# (the methods required to be considered a "custom range," eg for `Array#[]`.) See
|
|
140
|
+
# `to_helper` for details.
|
|
141
|
+
def range(begin_, end_, exclude_end = false, &)
|
|
142
|
+
::Blankity.blank do
|
|
143
|
+
define_method(:begin) { begin_ }
|
|
144
|
+
define_method(:end) { end_ }
|
|
145
|
+
define_method(:exclude_end?) { exclude_end }
|
|
146
|
+
|
|
147
|
+
class_exec(&block) if block
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
data/lib/blankity.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Generated from lib/blankity/blank.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Blankity
|
|
4
|
+
# A "blank slate" class which removes _all_ methods (from `BasicObject`) other than the "required"
|
|
5
|
+
# ones of `__send__` and `__id__`.
|
|
6
|
+
class Blank < BasicObject
|
|
7
|
+
# A helper method to define some `Kernel`methods on `self`
|
|
8
|
+
def __with_Object_methods__: (*untyped methods) -> untyped
|
|
9
|
+
|
|
10
|
+
# Same as `__with_Object_methods__`, but adds them to subclasses. This shouldn't
|
|
11
|
+
# be called on `Blankity::Blank` directly, as that affects subclasses
|
|
12
|
+
def self.__with_Object_methods__: (*untyped methods) -> untyped
|
|
13
|
+
|
|
14
|
+
# Helper method to create a new `Blank` with a block
|
|
15
|
+
def self.blank: () ?{ (?) -> untyped } -> untyped
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.blank: () -> untyped
|
|
19
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Generated from lib/blankity/tos.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Blankity
|
|
4
|
+
class ToI < Blank
|
|
5
|
+
# : (Integer) -> void
|
|
6
|
+
def initialize: (Integer) -> void
|
|
7
|
+
|
|
8
|
+
# : () -> Integer
|
|
9
|
+
def to_i: () -> Integer
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class ToInt < Blank
|
|
13
|
+
# : (Integer) -> void
|
|
14
|
+
def initialize: (Integer) -> void
|
|
15
|
+
|
|
16
|
+
# : () -> Integer
|
|
17
|
+
def to_int: () -> Integer
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class ToS < Blank
|
|
21
|
+
# : (String) -> void
|
|
22
|
+
def initialize: (String) -> void
|
|
23
|
+
|
|
24
|
+
# : () -> String
|
|
25
|
+
def to_s: () -> String
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class ToStr < Blank
|
|
29
|
+
# : (String) -> void
|
|
30
|
+
def initialize: (String) -> void
|
|
31
|
+
|
|
32
|
+
# : () -> String
|
|
33
|
+
def to_str: () -> String
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @rbs generic unchecked out T -- Type of elements
|
|
37
|
+
class ToA[unchecked out T] < Blank
|
|
38
|
+
# : (Array[T]) -> void
|
|
39
|
+
def initialize: (Array[T]) -> void
|
|
40
|
+
|
|
41
|
+
# : () -> String
|
|
42
|
+
def to_a: () -> String
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: blankity
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- SamW
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
email:
|
|
13
|
+
- mail@sampersand.me
|
|
14
|
+
executables: []
|
|
15
|
+
extensions: []
|
|
16
|
+
extra_rdoc_files: []
|
|
17
|
+
files:
|
|
18
|
+
- LICENSE.txt
|
|
19
|
+
- README.md
|
|
20
|
+
- Rakefile
|
|
21
|
+
- Steepfile
|
|
22
|
+
- lib/blankity.rb
|
|
23
|
+
- lib/blankity/blank.rb
|
|
24
|
+
- lib/blankity/classes.rb
|
|
25
|
+
- lib/blankity/to.rb
|
|
26
|
+
- lib/blankity/version.rb
|
|
27
|
+
- sig/generated/blankity.rbs
|
|
28
|
+
- sig/generated/blankity/blank.rbs
|
|
29
|
+
- sig/generated/blankity/tos.rbs
|
|
30
|
+
- sig/generated/blankity/version.rbs
|
|
31
|
+
homepage: https://github.com/sampersand/blankity/blob/master
|
|
32
|
+
licenses:
|
|
33
|
+
- MIT
|
|
34
|
+
metadata:
|
|
35
|
+
homepage_uri: https://github.com/sampersand/blankity/blob/master
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 3.1.0
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
requirements: []
|
|
50
|
+
rubygems_version: 3.7.0.dev
|
|
51
|
+
specification_version: 4
|
|
52
|
+
summary: Helpers for creating types which _only_ respond to specific conversion methods
|
|
53
|
+
test_files: []
|