blankity 0.0.2 → 0.1.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 +4 -4
- data/LICENSE.txt +1 -1
- data/Rakefile +2 -2
- data/Steepfile +1 -4
- data/lib/blankity/absolutely_blank.rb +21 -0
- data/lib/blankity/blank.rb +10 -0
- data/lib/blankity/classes.rb +115 -75
- data/lib/blankity/to.rb +35 -94
- data/lib/blankity/version.rb +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34a522794c85b7f50a815a2a17e455685e5fff40512134a8652d52705fd96946
|
|
4
|
+
data.tar.gz: 44fe6ca43f7a274e076b00c83fee4da89617102769007615a56f9e8ba8345876
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2679a4fc2901543f1df080226bcd8d41cde7fff84ffadf084a5a3b54509bc150e5e70ed9cc138624d3a9d9d0ba09f792b11ae7253894b9d35adab64a736c4eb3
|
|
7
|
+
data.tar.gz: 9102b667417681d9e6c52a83d3e2742513d0ff9a95efaa5925f913c9017c0a841c14ea1d414b36846797d885568547f99feffb729de7e13d012bab88508301df
|
data/LICENSE.txt
CHANGED
data/Rakefile
CHANGED
data/Steepfile
CHANGED
|
@@ -4,10 +4,7 @@ target :lib do
|
|
|
4
4
|
signature "sig"
|
|
5
5
|
ignore_signature "sig/test"
|
|
6
6
|
|
|
7
|
-
check
|
|
8
|
-
check "path/to/source.rb" # File name
|
|
9
|
-
check "app/models/**/*.rb" # Glob
|
|
10
|
-
# ignore "lib/templates/*.rb"
|
|
7
|
+
check 'lib'
|
|
11
8
|
|
|
12
9
|
# library "pathname" # Standard libraries
|
|
13
10
|
# library "strong_json" # Gems
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Blankity
|
|
2
|
+
# A Class that has _no_ instance methods on it whatsoever.
|
|
3
|
+
#
|
|
4
|
+
# This is actually pretty difficult to use properly, as some methods (e.g. +initialize+
|
|
5
|
+
# and +singleton_method_defined+) are expected by Ruby to always exist, and restrict a lot of
|
|
6
|
+
# builtin functionality. (For example, without +singleton_method_defined+, you can't actually
|
|
7
|
+
# define singleton methods _at all_.)
|
|
8
|
+
#
|
|
9
|
+
# @see Blank for a type which doesn't undefine these critical builtin methods
|
|
10
|
+
class AbsolutelyBlank < BasicObject
|
|
11
|
+
# We have to disable warnings for just this block, as Ruby warns for `undef`ing some methods
|
|
12
|
+
previous_warning, $-w = $-w, nil
|
|
13
|
+
|
|
14
|
+
(instance_methods + private_instance_methods).each do |name|
|
|
15
|
+
undef_method(name)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Set warnings to what they used to be
|
|
19
|
+
$-w = previous_warning
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/blankity/blank.rb
CHANGED
|
@@ -4,12 +4,22 @@
|
|
|
4
4
|
module Blankity
|
|
5
5
|
# A "blank slate" class which removes _all_ methods (from `BasicObject`) other than the "required"
|
|
6
6
|
# ones of `__send__` and `__id__`.
|
|
7
|
+
#
|
|
8
|
+
# Notably, it does not remove private instance methods, as Ruby actually requires some of them to
|
|
9
|
+
# function properly (e.g. {BasicObject#singleton_method_added}.)
|
|
7
10
|
class Blank < BasicObject
|
|
8
11
|
# Remove every method except for `__send__` and `__id__`
|
|
9
12
|
instance_methods.each do |name|
|
|
10
13
|
undef_method(name) unless name == :__send__ || name == :__id__
|
|
11
14
|
end
|
|
12
15
|
|
|
16
|
+
# Helper method to create a new instance
|
|
17
|
+
#
|
|
18
|
+
# @rbs: () ?{ (Blank) -> void } -> singleton(Blank)
|
|
19
|
+
def self.blank(&block)
|
|
20
|
+
::Class.new(self, &block).new
|
|
21
|
+
end
|
|
22
|
+
|
|
13
23
|
# A helper method to define some `Kernel`methods on `self`
|
|
14
24
|
def __with_Object_methods__(*methods)
|
|
15
25
|
dsm = ::Object.instance_method(:define_singleton_method).bind(self)
|
data/lib/blankity/classes.rb
CHANGED
|
@@ -2,162 +2,202 @@
|
|
|
2
2
|
# rbs_inline: enabled
|
|
3
3
|
|
|
4
4
|
module Blankity
|
|
5
|
-
|
|
5
|
+
# BlankValue is a superclass of the +ToXXX+ classes, which consolidates their initialization
|
|
6
|
+
# into one convenient place
|
|
7
|
+
#
|
|
8
|
+
# @rbs generic T -- type of @__value__
|
|
9
|
+
class BlankValue < Blank
|
|
10
|
+
# @rbs @__value__: T
|
|
11
|
+
|
|
12
|
+
DEFINE_SINGLETON_METHOD = ::Kernel.instance_method(:define_singleton_method)
|
|
13
|
+
private_constant :DEFINE_SINGLETON_METHOD
|
|
14
|
+
|
|
15
|
+
# Creates a new {BlankValue}, and defining singleton methods depending on the parameters
|
|
16
|
+
#
|
|
17
|
+
# @param value [T] the backing value for this class
|
|
18
|
+
# @param methods [Array[interned]] a list of methods to define on +self+ that will just forward
|
|
19
|
+
# everything to +value.<method>+
|
|
20
|
+
# @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
|
|
21
|
+
# type can be used as a key in +Hash+es
|
|
22
|
+
# @yield [] if a block is given, runs it via +instance_exec+.
|
|
23
|
+
#
|
|
24
|
+
# @rbs (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: self] -> void } -> void
|
|
6
25
|
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
26
|
@__value__ = value
|
|
11
27
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
define_singleton_method(:inspect) { to_method.to_s }
|
|
15
|
-
define_method(to_method) { value }
|
|
28
|
+
# If `hash` is supplied, then add `hash` and `eql?` to the list of methods to define
|
|
29
|
+
methods |= %i[hash eql?] if hash
|
|
16
30
|
|
|
17
|
-
# For all the `methods` methods, fetch its definition from `value` and use that as the
|
|
18
|
-
# definition
|
|
19
31
|
methods.each do |method|
|
|
20
|
-
|
|
32
|
+
# We can use `.method` instead of querying `Kernel` because all types that are used here
|
|
33
|
+
# inherit from `Object`.
|
|
34
|
+
DEFINE_SINGLETON_METHOD.bind_call(self, method, &@__value__.method(method))
|
|
21
35
|
end
|
|
22
36
|
|
|
23
|
-
|
|
24
|
-
class_exec(&block) if block
|
|
37
|
+
instance_exec(&block) if block
|
|
25
38
|
end
|
|
26
39
|
end
|
|
27
40
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
# A Class which exclusively defines +#to_i+; it implements RBS's +_ToI+ interface.
|
|
42
|
+
#
|
|
43
|
+
# @rbs inherits BlankValue[Integer]
|
|
44
|
+
class ToI < BlankValue
|
|
32
45
|
#: () -> Integer
|
|
33
46
|
def to_i = @__value__
|
|
34
47
|
end
|
|
35
48
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
# A Class which exclusively defines +#to_int+; it implements RBS's +_ToInt+ interface.
|
|
50
|
+
#
|
|
51
|
+
# @rbs inherits BlankValue[Integer]
|
|
52
|
+
class ToInt < BlankValue
|
|
40
53
|
#: () -> Integer
|
|
41
54
|
def to_int = @__value__
|
|
42
55
|
end
|
|
43
56
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
57
|
+
# A Class which exclusively defines +#to_s+; it implements RBS's +_ToS+ interface.
|
|
58
|
+
#
|
|
59
|
+
# @rbs inherits BlankValue[String]
|
|
60
|
+
class ToS < BlankValue
|
|
48
61
|
#: () -> String
|
|
49
62
|
def to_s = @__value__
|
|
50
63
|
end
|
|
51
64
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
65
|
+
# A Class which exclusively defines +#to_str+; it implements RBS's +_ToStr+ interface.
|
|
66
|
+
#
|
|
67
|
+
# @rbs inherits BlankValue[String]
|
|
68
|
+
class ToStr < BlankValue
|
|
56
69
|
#: () -> String
|
|
57
70
|
def to_str = @__value__
|
|
58
71
|
end
|
|
59
72
|
|
|
73
|
+
# A Class which exclusively defines +#to_a+; it implements RBS's +_ToA[T]+ interface.
|
|
74
|
+
#
|
|
60
75
|
# @rbs generic unchecked out T -- Type of elements
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def initialize(value) = @__value__ = value
|
|
64
|
-
|
|
76
|
+
# @rbs inherits BlankValue[Array[T]]
|
|
77
|
+
class ToA < BlankValue
|
|
65
78
|
#: () -> Array[T]
|
|
66
79
|
def to_a = @__value__
|
|
67
80
|
end
|
|
68
81
|
|
|
82
|
+
# A Class which exclusively defines +#to_ary+; it implements RBS's +_ToAry[T]+ interface.
|
|
83
|
+
#
|
|
69
84
|
# @rbs generic unchecked out T -- Type of elements
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def initialize(value) = @__value__ = value
|
|
73
|
-
|
|
85
|
+
# @rbs inherits BlankValue[Array[T]]
|
|
86
|
+
class ToAry < BlankValue
|
|
74
87
|
#: () -> Array[T]
|
|
75
88
|
def to_ary = @__value__
|
|
76
89
|
end
|
|
77
90
|
|
|
91
|
+
# A Class which exclusively defines +#to_h+; it implements RBS's +_ToH[K, V]+ interface.
|
|
92
|
+
#
|
|
78
93
|
# @rbs generic unchecked out K -- Type of Key
|
|
79
94
|
# @rbs generic unchecked out V -- Type of Value
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def initialize(value) = @__value__ = value
|
|
83
|
-
|
|
95
|
+
# @rbs inherits BlankValue[Hash[K, V]]
|
|
96
|
+
class ToH < BlankValue
|
|
84
97
|
#: () -> Hash[K, V]
|
|
85
98
|
def to_h = @__value__
|
|
86
99
|
end
|
|
87
100
|
|
|
101
|
+
# A Class which exclusively defines +#to_hash+; it implements RBS's +_ToHash[K, V]+ interface.
|
|
102
|
+
#
|
|
88
103
|
# @rbs generic unchecked out K -- Type of Key
|
|
89
104
|
# @rbs generic unchecked out V -- Type of Value
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def initialize(value) = @__value__ = value
|
|
93
|
-
|
|
105
|
+
# @rbs inherits BlankValue[Hash[K, V]]
|
|
106
|
+
class ToHash < BlankValue
|
|
94
107
|
#: () -> Hash[K, V]
|
|
95
108
|
def to_hash = @__value__
|
|
96
109
|
end
|
|
97
110
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
111
|
+
# A Class which exclusively defines +#to_sym+; it implements RBS's +_ToSym+ interface.
|
|
112
|
+
#
|
|
113
|
+
# @rbs inherits BlankValue[Symbol]
|
|
114
|
+
class ToSym < BlankValue
|
|
102
115
|
#: () -> Symbol
|
|
103
116
|
def to_sym = @__value__
|
|
104
117
|
end
|
|
105
118
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
119
|
+
# A Class which exclusively defines +#to_r+; it implements RBS's +_ToR+ interface.
|
|
120
|
+
#
|
|
121
|
+
# @rbs inherits BlankValue[Rational]
|
|
122
|
+
class ToR < BlankValue
|
|
110
123
|
#: () -> Rational
|
|
111
124
|
def to_r = @__value__
|
|
112
125
|
end
|
|
113
126
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
127
|
+
# A Class which exclusively defines +#to_c+; it implements RBS's +_ToC+ interface.
|
|
128
|
+
#
|
|
129
|
+
# @rbs inherits BlankValue[Complex]
|
|
130
|
+
class ToC < BlankValue
|
|
118
131
|
#: () -> Complex
|
|
119
132
|
def to_C = @__value__
|
|
120
133
|
end
|
|
121
134
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
# A Class which exclusively defines +#to_f+; it implements RBS's +_ToF+ interface.
|
|
136
|
+
#
|
|
137
|
+
# @rbs inherits BlankValue[Float]
|
|
138
|
+
class ToF < BlankValue
|
|
126
139
|
#: () -> Float
|
|
127
140
|
def to_f = @__value__
|
|
128
141
|
end
|
|
129
142
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
143
|
+
# A Class which exclusively defines +#to_regexp+; it implements RBS's +Regexp::_ToRegexp+ interface.
|
|
144
|
+
#
|
|
145
|
+
# @rbs inherits BlankValue[Regexp]
|
|
146
|
+
class ToRegexp < BlankValue
|
|
134
147
|
#: () -> Regexp
|
|
135
148
|
def to_regexp = @__value__
|
|
136
149
|
end
|
|
137
150
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
151
|
+
# A Class which exclusively defines +#to_path+; it implements RBS's +_ToPath+ interface.
|
|
152
|
+
#
|
|
153
|
+
# @rbs inherits BlankValue[String]
|
|
154
|
+
class ToPath < BlankValue
|
|
142
155
|
#: () -> String
|
|
143
156
|
def to_path = @__value__
|
|
144
157
|
end
|
|
145
158
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
159
|
+
# A Class which exclusively defines +#to_io+; it implements RBS's +_ToIO+ interface.
|
|
160
|
+
#
|
|
161
|
+
# @rbs inherits BlankValue[IO]
|
|
162
|
+
class ToIO < BlankValue
|
|
150
163
|
#: () -> IO
|
|
151
164
|
def to_io = @__value__
|
|
152
165
|
end
|
|
153
166
|
|
|
167
|
+
# A Class which exclusively defines +#to_proc+; it implements RBS's +_ToProc+ interface.
|
|
168
|
+
#
|
|
169
|
+
# @rbs inherits BlankValue[Proc]
|
|
170
|
+
class ToProc < BlankValue
|
|
171
|
+
#: () -> Proc
|
|
172
|
+
def to_proc = @__value__
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# A Class which defines `#begin`, `#end`, and `#exclude_end?`. It implements RBS's +_Range[T]+
|
|
176
|
+
# interface.
|
|
177
|
+
#
|
|
154
178
|
# @rbs generic out T -- Type to iterate over
|
|
155
179
|
class Range < Blank
|
|
180
|
+
# @rbs @begin: T?
|
|
181
|
+
# @rbs @end: T?
|
|
182
|
+
# @rbs @exclude_end: bool
|
|
183
|
+
|
|
156
184
|
#: (T?, T?, ?bool) -> void
|
|
157
|
-
def initialize(begin_, end_, exclude_end = false)
|
|
185
|
+
def initialize(begin_, end_, exclude_end = false, methods: [], hash: false, &block)
|
|
158
186
|
@__begin__ = begin_
|
|
159
187
|
@__end__ = end_
|
|
160
188
|
@__exclude_end__ = exclude_end
|
|
189
|
+
|
|
190
|
+
# If `hash` is supplied, then add `hash` and `eql?` to the list of methods to define
|
|
191
|
+
methods |= %i[hash eql?] if hash
|
|
192
|
+
|
|
193
|
+
methods.each do |method|
|
|
194
|
+
p method
|
|
195
|
+
# We can use `.method` instead of querying `Kernel` because all types that are used here
|
|
196
|
+
# inherit from `Object`.
|
|
197
|
+
DEFINE_SINGLETON_METHOD.bind_call(self, method, &@__value__.method(method))
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
instance_exec(&block) if block
|
|
161
201
|
end
|
|
162
202
|
|
|
163
203
|
#: () -> T?
|
|
@@ -167,6 +207,6 @@ module Blankity
|
|
|
167
207
|
def end = @__end__
|
|
168
208
|
|
|
169
209
|
#: () -> bool
|
|
170
|
-
def exclude_end = @__exclude_end__
|
|
210
|
+
def exclude_end? = @__exclude_end__
|
|
171
211
|
end
|
|
172
212
|
end
|
data/lib/blankity/to.rb
CHANGED
|
@@ -4,62 +4,21 @@ module Blankity
|
|
|
4
4
|
module To
|
|
5
5
|
module_function
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
7
|
+
def i(value, ...) = ToI.new(value.to_i, ...)
|
|
8
|
+
def int(value, ...) = ToInt.new(value.to_int, ...)
|
|
9
|
+
def s(value, ...) = ToS.new(value.to_s, ...)
|
|
10
|
+
def str(value, ...) = ToStr.new(value.to_str, ...)
|
|
52
11
|
|
|
53
12
|
# Create a type which _only_ responds to `.to_a`. See `to_helper` for details.
|
|
54
13
|
#
|
|
55
14
|
# This supports `a(1, 2, 3)` as a convenient shorthand for `a([1, 2, 3])`. To
|
|
56
15
|
# create a `.to_a` that returns an array containing just an array, just use `a([array])`.
|
|
57
16
|
def a(*elements, **, &)
|
|
58
|
-
if elements.length == 1
|
|
59
|
-
|
|
60
|
-
else
|
|
61
|
-
to_helper(:to_a, elements, **, &)
|
|
17
|
+
if elements.length == 1 && defined?(elements[0].to_a)
|
|
18
|
+
elements = elements[0].to_a
|
|
62
19
|
end
|
|
20
|
+
|
|
21
|
+
ToA.new(elements, **, &)
|
|
63
22
|
end
|
|
64
23
|
|
|
65
24
|
# Create a type which _only_ responds to `.to_ary`. See `to_helper` for details.
|
|
@@ -67,11 +26,11 @@ module Blankity
|
|
|
67
26
|
# This supports `ary(1, 2, 3)` as a convenient shorthand for `ary([1, 2, 3])`. To
|
|
68
27
|
# create a `.to_ary` that returns an array containing just an array, use `ary([array])`.
|
|
69
28
|
def ary(*elements, **, &)
|
|
70
|
-
if elements.length == 1
|
|
71
|
-
|
|
72
|
-
else
|
|
73
|
-
to_helper(:to_ary, elements, **, &)
|
|
29
|
+
if elements.length == 1 && defined?(elements[0].to_ary)
|
|
30
|
+
elements = elements[0].to_ary
|
|
74
31
|
end
|
|
32
|
+
|
|
33
|
+
ToAry.new(elements, **, &)
|
|
75
34
|
end
|
|
76
35
|
|
|
77
36
|
# Create a type which _only_ responds to `.to_h`. See `to_helper` for details.
|
|
@@ -81,9 +40,9 @@ module Blankity
|
|
|
81
40
|
# to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
|
|
82
41
|
def h(hash = nohash=true, **, &)
|
|
83
42
|
if nohash
|
|
84
|
-
|
|
43
|
+
ToH.new({**}, &)
|
|
85
44
|
else
|
|
86
|
-
|
|
45
|
+
ToH.new(hash.to_h, **, &)
|
|
87
46
|
end
|
|
88
47
|
end
|
|
89
48
|
|
|
@@ -94,58 +53,40 @@ module Blankity
|
|
|
94
53
|
# to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
|
|
95
54
|
def hash(hash = nohash=true, **, &)
|
|
96
55
|
if nohash
|
|
97
|
-
|
|
56
|
+
ToHash.new({**}, &)
|
|
98
57
|
else
|
|
99
|
-
|
|
58
|
+
ToHash.new(hash.to_hash, **, &)
|
|
100
59
|
end
|
|
101
60
|
end
|
|
102
61
|
|
|
103
|
-
|
|
104
|
-
def
|
|
105
|
-
|
|
106
|
-
|
|
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
|
|
62
|
+
def sym(value, ...) = ToSym.new(value.to_sym, ...)
|
|
63
|
+
def r(value, ...) = ToR.new(value.to_r, ...)
|
|
64
|
+
def c(value, ...) = ToC.new(value.to_c, ...)
|
|
65
|
+
def f(value, ...) = ToF.new(value.to_f, ...)
|
|
66
|
+
def regexp(value, ...) = ToRegexp.new(value.to_regexp, ...)
|
|
127
67
|
|
|
128
|
-
# Create a type which _only_ responds to `.to_path`. See `to_helper` for details.
|
|
129
68
|
def path(value, ...)
|
|
130
|
-
|
|
69
|
+
ToPath.new(defined?(value.to_path) ? value.to_path : String(value), ...)
|
|
131
70
|
end
|
|
132
71
|
|
|
133
|
-
|
|
134
|
-
def
|
|
135
|
-
|
|
72
|
+
def io(value, ...) = ToIO.new(value.to_io, ...)
|
|
73
|
+
def proc(proc = noproc=true, **, &block)
|
|
74
|
+
if noproc
|
|
75
|
+
unless block_given?
|
|
76
|
+
raise ArgumentError, 'if an explicit proc is omitted, a block must be passed'
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
ToProc.new(block, **)
|
|
80
|
+
else
|
|
81
|
+
ToProc.new(proc.to_proc, **, &block)
|
|
82
|
+
end
|
|
136
83
|
end
|
|
137
84
|
|
|
138
85
|
# Create a type which _only_ responds to `.begin`, `.end`, and `.exclude_end?`
|
|
139
86
|
# (the methods required to be considered a "custom range," eg for `Array#[]`.) See
|
|
140
87
|
# `to_helper` for details.
|
|
141
|
-
def range(begin_, end_, exclude_end = false,
|
|
142
|
-
|
|
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
|
|
88
|
+
def range(begin_, end_, exclude_end = false, ...)
|
|
89
|
+
Range.new(begin_, end_, exclude_end, ...)
|
|
149
90
|
end
|
|
150
91
|
end
|
|
151
92
|
end
|
data/lib/blankity/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: blankity
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Sam Westerman
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
description: |
|
|
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.
|
|
15
|
+
email: mail@sampersand.me
|
|
14
16
|
executables: []
|
|
15
17
|
extensions: []
|
|
16
18
|
extra_rdoc_files: []
|
|
@@ -20,6 +22,7 @@ files:
|
|
|
20
22
|
- Rakefile
|
|
21
23
|
- Steepfile
|
|
22
24
|
- lib/blankity.rb
|
|
25
|
+
- lib/blankity/absolutely_blank.rb
|
|
23
26
|
- lib/blankity/blank.rb
|
|
24
27
|
- lib/blankity/classes.rb
|
|
25
28
|
- lib/blankity/to.rb
|
|
@@ -28,11 +31,11 @@ files:
|
|
|
28
31
|
- sig/generated/blankity/blank.rbs
|
|
29
32
|
- sig/generated/blankity/tos.rbs
|
|
30
33
|
- sig/generated/blankity/version.rbs
|
|
31
|
-
homepage: https://github.com/sampersand/blankity
|
|
34
|
+
homepage: https://github.com/sampersand/blankity
|
|
32
35
|
licenses:
|
|
33
36
|
- MIT
|
|
34
37
|
metadata:
|
|
35
|
-
homepage_uri: https://github.com/sampersand/blankity
|
|
38
|
+
homepage_uri: https://github.com/sampersand/blankity
|
|
36
39
|
rdoc_options: []
|
|
37
40
|
require_paths:
|
|
38
41
|
- lib
|
|
@@ -40,7 +43,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
40
43
|
requirements:
|
|
41
44
|
- - ">="
|
|
42
45
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: 3.
|
|
46
|
+
version: 3.2.0
|
|
44
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
48
|
requirements:
|
|
46
49
|
- - ">="
|
|
@@ -49,5 +52,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
49
52
|
requirements: []
|
|
50
53
|
rubygems_version: 3.7.0.dev
|
|
51
54
|
specification_version: 4
|
|
52
|
-
summary:
|
|
55
|
+
summary: Provides "blank" objects which *only* supply conversion methods
|
|
53
56
|
test_files: []
|