blankity 0.9.2 → 0.10.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/README.md +1 -1
- data/lib/blankity/blank.rb +26 -45
- data/lib/blankity/classes.rb +17 -17
- data/lib/blankity/to.rb +1 -1
- data/lib/blankity/version.rb +1 -1
- data/lib/blankity.rb +6 -1
- data/sig/generated/blankity/blank.rbs +6 -23
- data/sig/test/test/test_blank.rbs +0 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77c386d3e2995f2bd9b923e9454b6ea7eee52ab56b0bee93365c38cf3c0c7116
|
|
4
|
+
data.tar.gz: b590b899c896efe9d843ee456517a30822e85220a89e8ae890fba831975159fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 614a8f62d477bac3d9809ac2e37201242fe34bca08693af20dd5089f6be99e5b1ef336971e31a0e3c02f355aa572420353288d747767a8f9ae2aa431e62ee6a0
|
|
7
|
+
data.tar.gz: 3044675608037373cb1d7ff3ff9ee40729289e0d68b3c170cdb8c5302013b70844d556fc359be50281598f598d5afa8b02c713d011b224c1cbcaeefae9b2b773
|
data/README.md
CHANGED
|
@@ -24,7 +24,7 @@ p defined?(blank.==) #=> nil
|
|
|
24
24
|
p defined?(blank.inspect) #=> nil
|
|
25
25
|
|
|
26
26
|
# Include specific `Object` methods:
|
|
27
|
-
blank = Blankity::Blank.new(
|
|
27
|
+
blank = Blankity::Blank.new(with: [:==])
|
|
28
28
|
p blank == blank #=> true
|
|
29
29
|
|
|
30
30
|
# Also supports blocks, which are `instance_exec`ed
|
data/lib/blankity/blank.rb
CHANGED
|
@@ -12,76 +12,57 @@ module Blankity
|
|
|
12
12
|
# - Private methods are not undefined, as each one of them is expected to be present (most of them
|
|
13
13
|
# are hooks, eg +singleton_method_added+), and aren't easily accessible from external classes.
|
|
14
14
|
#
|
|
15
|
-
# To make using +Blank+ easier, its constructor allows you to pass a +
|
|
15
|
+
# To make using +Blank+ easier, its constructor allows you to pass a +with:+ keyword argument,
|
|
16
16
|
# which will define singleton methods based on {Object}.
|
|
17
17
|
class Blank < BasicObject
|
|
18
|
-
#
|
|
18
|
+
# Define top-level methods that are annoying to not have present.
|
|
19
|
+
|
|
20
|
+
# @rbs!
|
|
21
|
+
# def __define_singleton_method__: (interned name, Method | UnboundMethod | Proc method) -> Symbol
|
|
22
|
+
# | (interned name) { (?) [self: self] -> untyped } -> Symbol
|
|
23
|
+
# def __instance_exec__: [T] (*untyped, **untyped) { (?) [self: self] -> T } -> T
|
|
24
|
+
define_method :__define_singleton_method__, ::Kernel.instance_method(:define_singleton_method)
|
|
25
|
+
alias_method :__instance_exec__, :instance_exec # Use `alias_method` instead of `alias` so rbs-inline won't pick it up
|
|
26
|
+
|
|
27
|
+
# Remove every other public and protected method that we inherit, except for `__xyz__` methods
|
|
19
28
|
instance_methods.each do |name|
|
|
20
29
|
undef_method(name) unless name.match?(/\A__.*__\z/)
|
|
21
30
|
end
|
|
22
31
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
class << self
|
|
33
|
+
# Alias for `new`
|
|
34
|
+
alias blank new
|
|
35
|
+
end
|
|
27
36
|
|
|
28
37
|
# Creates a new {BlankValue}, and defining singleton methods depending on the parameters
|
|
29
38
|
#
|
|
30
|
-
# @param
|
|
31
|
-
# @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +
|
|
39
|
+
# @param with [Array[interned]] a list of {Object} methods to define on +self+.
|
|
40
|
+
# @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +with+ so the resulting
|
|
32
41
|
# type can be used as a key in +Hash+es
|
|
33
|
-
# @yield [] if a block is given, runs it via +
|
|
42
|
+
# @yield [] if a block is given, runs it via +__instance_exec__+.
|
|
34
43
|
#
|
|
35
44
|
# === Example
|
|
36
45
|
# # Make a empty instance
|
|
37
46
|
# Blankity::Blank.new
|
|
38
47
|
#
|
|
39
48
|
# # Include `Object#inspect`, so we can print with `p`
|
|
40
|
-
# p Blankity::Blank.new(
|
|
49
|
+
# p Blankity::Blank.new(with: %i[inspect])
|
|
41
50
|
#
|
|
42
51
|
# # Define a singleton method
|
|
43
52
|
# p Blankity::Blank.new{ def cool?(other) = other == 3 }.cool?(3) #=> true
|
|
44
53
|
#
|
|
45
|
-
# @rbs (?
|
|
46
|
-
def initialize(
|
|
54
|
+
# @rbs (?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
55
|
+
def initialize(with: [], hash: false, &block)
|
|
47
56
|
# If `hash` is supplied, then add `hash` and `eql?` to the list of methods to define
|
|
48
|
-
|
|
57
|
+
with |= %i[hash eql?] if hash
|
|
49
58
|
|
|
50
59
|
# Define any object methods requested by the end-user
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# If a block's provided, then `instance_exec`
|
|
54
|
-
INSTANCE_EXEC.bind_call(self, &__any__ = block) if block
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# A helper method to define {Object} instance methods on +self+
|
|
58
|
-
#
|
|
59
|
-
# @param methods [*interned] The list of instance methods from {Object} to define
|
|
60
|
-
# @return [self]
|
|
61
|
-
#
|
|
62
|
-
# === Example
|
|
63
|
-
# # Make an empty instance
|
|
64
|
-
# blank = Blankity::Blank.blank
|
|
65
|
-
#
|
|
66
|
-
# # Make sure it's printable
|
|
67
|
-
# blank.__define_Object_methods__(:inspect, :==)
|
|
68
|
-
#
|
|
69
|
-
# # Now you can use them!
|
|
70
|
-
# fail unless blank == blank
|
|
71
|
-
# p blank
|
|
72
|
-
#
|
|
73
|
-
# @rbs (*interned) -> self
|
|
74
|
-
def __define_Object_methods__(*methods)
|
|
75
|
-
methods.each do |method|
|
|
76
|
-
DEFINE_SINGLETON_METHOD.bind_call(self, method, ::Object.instance_method(method).bind(self))
|
|
60
|
+
with.each do |method|
|
|
61
|
+
__define_singleton_method__(method, ::Object.instance_method(method).bind(self))
|
|
77
62
|
end
|
|
78
63
|
|
|
79
|
-
|
|
64
|
+
# If a block's provided, then `instance_exec`
|
|
65
|
+
__instance_exec__(&__any__ = block) if block
|
|
80
66
|
end
|
|
81
67
|
end
|
|
82
|
-
|
|
83
|
-
# Shorthand constructor {Blankity::Blank}.
|
|
84
|
-
#
|
|
85
|
-
# @rbs (?methods: Array[interned], ?hash: bool) ?{ () [self: Blank] -> void } -> Blank
|
|
86
|
-
def self.blank(...) = Blank.new(...)
|
|
87
68
|
end
|
data/lib/blankity/classes.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Blankity
|
|
|
8
8
|
|
|
9
9
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
10
10
|
#
|
|
11
|
-
# @rbs (Integer, ?
|
|
11
|
+
# @rbs (Integer, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
12
12
|
def initialize(value, ...)
|
|
13
13
|
@__value__ = value
|
|
14
14
|
super(...)
|
|
@@ -24,7 +24,7 @@ module Blankity
|
|
|
24
24
|
|
|
25
25
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
26
26
|
#
|
|
27
|
-
# @rbs (Integer, ?
|
|
27
|
+
# @rbs (Integer, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
28
28
|
def initialize(value, ...)
|
|
29
29
|
@__value__ = value
|
|
30
30
|
super(...)
|
|
@@ -40,7 +40,7 @@ module Blankity
|
|
|
40
40
|
|
|
41
41
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
42
42
|
#
|
|
43
|
-
# @rbs (String, ?
|
|
43
|
+
# @rbs (String, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
44
44
|
def initialize(value, ...)
|
|
45
45
|
@__value__ = value
|
|
46
46
|
super(...)
|
|
@@ -56,7 +56,7 @@ module Blankity
|
|
|
56
56
|
|
|
57
57
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
58
58
|
#
|
|
59
|
-
# @rbs (String, ?
|
|
59
|
+
# @rbs (String, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
60
60
|
def initialize(value, ...)
|
|
61
61
|
@__value__ = value
|
|
62
62
|
super(...)
|
|
@@ -74,7 +74,7 @@ module Blankity
|
|
|
74
74
|
|
|
75
75
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
76
76
|
#
|
|
77
|
-
# @rbs (Array[T], ?
|
|
77
|
+
# @rbs (Array[T], ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
78
78
|
def initialize(value, ...)
|
|
79
79
|
@__value__ = value
|
|
80
80
|
super(...)
|
|
@@ -92,7 +92,7 @@ module Blankity
|
|
|
92
92
|
|
|
93
93
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
94
94
|
#
|
|
95
|
-
# @rbs (Array[T], ?
|
|
95
|
+
# @rbs (Array[T], ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
96
96
|
def initialize(value, ...)
|
|
97
97
|
@__value__ = value
|
|
98
98
|
super(...)
|
|
@@ -111,7 +111,7 @@ module Blankity
|
|
|
111
111
|
|
|
112
112
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
113
113
|
#
|
|
114
|
-
# @rbs (Hash[K, V], ?
|
|
114
|
+
# @rbs (Hash[K, V], ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
115
115
|
def initialize(value, ...)
|
|
116
116
|
@__value__ = value
|
|
117
117
|
super(...)
|
|
@@ -130,7 +130,7 @@ module Blankity
|
|
|
130
130
|
|
|
131
131
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
132
132
|
#
|
|
133
|
-
# @rbs (Hash[K, V], ?
|
|
133
|
+
# @rbs (Hash[K, V], ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
134
134
|
def initialize(value, ...)
|
|
135
135
|
@__value__ = value
|
|
136
136
|
super(...)
|
|
@@ -146,7 +146,7 @@ module Blankity
|
|
|
146
146
|
|
|
147
147
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
148
148
|
#
|
|
149
|
-
# @rbs (Symbol, ?
|
|
149
|
+
# @rbs (Symbol, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
150
150
|
def initialize(value, ...)
|
|
151
151
|
@__value__ = value
|
|
152
152
|
super(...)
|
|
@@ -162,7 +162,7 @@ module Blankity
|
|
|
162
162
|
|
|
163
163
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
164
164
|
#
|
|
165
|
-
# @rbs (Rational, ?
|
|
165
|
+
# @rbs (Rational, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
166
166
|
def initialize(value, ...)
|
|
167
167
|
@__value__ = value
|
|
168
168
|
super(...)
|
|
@@ -178,7 +178,7 @@ module Blankity
|
|
|
178
178
|
|
|
179
179
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
180
180
|
#
|
|
181
|
-
# @rbs (Complex, ?
|
|
181
|
+
# @rbs (Complex, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
182
182
|
def initialize(value, ...)
|
|
183
183
|
@__value__ = value
|
|
184
184
|
super(...)
|
|
@@ -194,7 +194,7 @@ module Blankity
|
|
|
194
194
|
|
|
195
195
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
196
196
|
#
|
|
197
|
-
# @rbs (Float, ?
|
|
197
|
+
# @rbs (Float, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
198
198
|
def initialize(value, ...)
|
|
199
199
|
@__value__ = value
|
|
200
200
|
super(...)
|
|
@@ -210,7 +210,7 @@ module Blankity
|
|
|
210
210
|
|
|
211
211
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
212
212
|
#
|
|
213
|
-
# @rbs (Regexp, ?
|
|
213
|
+
# @rbs (Regexp, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
214
214
|
def initialize(value, ...)
|
|
215
215
|
@__value__ = value
|
|
216
216
|
super(...)
|
|
@@ -226,7 +226,7 @@ module Blankity
|
|
|
226
226
|
|
|
227
227
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
228
228
|
#
|
|
229
|
-
# @rbs (String, ?
|
|
229
|
+
# @rbs (String, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
230
230
|
def initialize(value, ...)
|
|
231
231
|
@__value__ = value
|
|
232
232
|
super(...)
|
|
@@ -242,7 +242,7 @@ module Blankity
|
|
|
242
242
|
|
|
243
243
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
244
244
|
#
|
|
245
|
-
# @rbs (IO, ?
|
|
245
|
+
# @rbs (IO, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
246
246
|
def initialize(value, ...)
|
|
247
247
|
@__value__ = value
|
|
248
248
|
super(...)
|
|
@@ -258,7 +258,7 @@ module Blankity
|
|
|
258
258
|
|
|
259
259
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
260
260
|
#
|
|
261
|
-
# @rbs (Proc, ?
|
|
261
|
+
# @rbs (Proc, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
262
262
|
def initialize(value, ...)
|
|
263
263
|
@__value__ = value
|
|
264
264
|
super(...)
|
|
@@ -279,7 +279,7 @@ module Blankity
|
|
|
279
279
|
|
|
280
280
|
# Creates a new instance; any additional arguments or block are passed to {Blank#initialize}.
|
|
281
281
|
#
|
|
282
|
-
# @rbs (T?, T?, ?bool, ?
|
|
282
|
+
# @rbs (T?, T?, ?bool, ?with: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
283
283
|
def initialize(begin_, end_, exclude_end = false, ...)
|
|
284
284
|
@__begin__ = begin_
|
|
285
285
|
@__end__ = end_
|
data/lib/blankity/to.rb
CHANGED
|
@@ -131,7 +131,7 @@ module Blankity
|
|
|
131
131
|
#
|
|
132
132
|
# @rbs (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
|
|
133
133
|
# | (?methods: Array[interned], ?hash: bool) { (?) -> untyped } -> ToProc
|
|
134
|
-
def proc(proc = nil, **, &block)
|
|
134
|
+
def self.proc(proc = nil, **, &block)
|
|
135
135
|
if proc
|
|
136
136
|
ToProc.new(proc.to_proc, **, &block)
|
|
137
137
|
elsif !block_given?
|
data/lib/blankity/version.rb
CHANGED
data/lib/blankity.rb
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
# rbs_inline: enabled
|
|
3
3
|
|
|
4
|
-
module Blankity
|
|
4
|
+
module Blankity
|
|
5
|
+
# Shorthand constructor {Blankity::Blank}.
|
|
6
|
+
#
|
|
7
|
+
# @rbs (?with: Array[interned], ?hash: bool) ?{ () [self: Blank] -> void } -> Blank
|
|
8
|
+
def self.blank(...) = Blank.new(...)
|
|
9
|
+
end
|
|
5
10
|
|
|
6
11
|
require_relative 'blankity/version'
|
|
7
12
|
require_relative 'blankity/top'
|
|
@@ -14,17 +14,19 @@ module Blankity
|
|
|
14
14
|
# To make using +Blank+ easier, its constructor allows you to pass a +methods:+ keyword argument,
|
|
15
15
|
# which will define singleton methods based on {Object}.
|
|
16
16
|
class Blank < BasicObject
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
def __define_singleton_method__: (interned name, Method | UnboundMethod | Proc method) -> Symbol
|
|
18
|
+
| (interned name) { (?) [self: self] -> untyped } -> Symbol
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
def __instance_exec__: [T] (*untyped, **untyped) { (?) [self: self] -> T } -> T
|
|
21
|
+
|
|
22
|
+
alias self.blank self.new
|
|
21
23
|
|
|
22
24
|
# Creates a new {BlankValue}, and defining singleton methods depending on the parameters
|
|
23
25
|
#
|
|
24
26
|
# @param methods [Array[interned]] a list of {Object} methods to define on +self+.
|
|
25
27
|
# @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
|
|
26
28
|
# type can be used as a key in +Hash+es
|
|
27
|
-
# @yield [] if a block is given, runs it via +
|
|
29
|
+
# @yield [] if a block is given, runs it via +__instance_exec__+.
|
|
28
30
|
#
|
|
29
31
|
# === Example
|
|
30
32
|
# # Make a empty instance
|
|
@@ -38,25 +40,6 @@ module Blankity
|
|
|
38
40
|
#
|
|
39
41
|
# @rbs (?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
40
42
|
def initialize: (?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
41
|
-
|
|
42
|
-
# A helper method to define {Object} instance methods on +self+
|
|
43
|
-
#
|
|
44
|
-
# @param methods [*interned] The list of instance methods from {Object} to define
|
|
45
|
-
# @return [self]
|
|
46
|
-
#
|
|
47
|
-
# === Example
|
|
48
|
-
# # Make an empty instance
|
|
49
|
-
# blank = Blankity::Blank.blank
|
|
50
|
-
#
|
|
51
|
-
# # Make sure it's printable
|
|
52
|
-
# blank.__define_Object_methods__(:inspect, :==)
|
|
53
|
-
#
|
|
54
|
-
# # Now you can use them!
|
|
55
|
-
# fail unless blank == blank
|
|
56
|
-
# p blank
|
|
57
|
-
#
|
|
58
|
-
# @rbs (*interned) -> self
|
|
59
|
-
def __define_Object_methods__: (*interned) -> self
|
|
60
43
|
end
|
|
61
44
|
|
|
62
45
|
# Shorthand constructor {Blankity::Blank}.
|