blankity 0.9.2 → 0.9.3
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/lib/blankity/blank.rb +14 -33
- data/lib/blankity/to.rb +1 -1
- data/lib/blankity/version.rb +1 -1
- data/sig/generated/blankity/blank.rbs +4 -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: 0a2474babea0e68bddb79670ae6b5680fd0b2be07677b502071d2d9a1abf4eea
|
|
4
|
+
data.tar.gz: 6898a094071b9dfa0bd62863ee9b64cf5823c664d84a77913597c999826e92e8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b0ff3504d136935da61af9c623b4e09a6765c5cb865ce97ee0ef31d82f44b9355109c221ec68432e7c0a0d26db1ed56ca54066e9a2f40ee8fead43a3e1aec222
|
|
7
|
+
data.tar.gz: 98067d34173efe13142af36e399ee04ed95905924e4727995c1b0f09ded1cf679979fdca7b3718fbf03dffb574b6b6ff1e7f440b95cc2ce19b2fbc1ce0f6915f
|
data/lib/blankity/blank.rb
CHANGED
|
@@ -15,22 +15,26 @@ module Blankity
|
|
|
15
15
|
# To make using +Blank+ easier, its constructor allows you to pass a +methods:+ 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
|
-
# Declare these as constants so we don't constantly look them up.
|
|
24
|
-
DEFINE_SINGLETON_METHOD = ::Object.instance_method(:define_singleton_method) #: UnboundMethod
|
|
25
|
-
INSTANCE_EXEC = ::Object.instance_method(:instance_exec) #: UnboundMethod
|
|
26
|
-
private_constant :DEFINE_SINGLETON_METHOD, :INSTANCE_EXEC
|
|
27
|
-
|
|
28
32
|
# Creates a new {BlankValue}, and defining singleton methods depending on the parameters
|
|
29
33
|
#
|
|
30
34
|
# @param methods [Array[interned]] a list of {Object} methods to define on +self+.
|
|
31
35
|
# @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
|
|
32
36
|
# type can be used as a key in +Hash+es
|
|
33
|
-
# @yield [] if a block is given, runs it via +
|
|
37
|
+
# @yield [] if a block is given, runs it via +__instance_exec__+.
|
|
34
38
|
#
|
|
35
39
|
# === Example
|
|
36
40
|
# # Make a empty instance
|
|
@@ -48,35 +52,12 @@ module Blankity
|
|
|
48
52
|
methods |= %i[hash eql?] if hash
|
|
49
53
|
|
|
50
54
|
# Define any object methods requested by the end-user
|
|
51
|
-
__define_Object_methods__(*methods)
|
|
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
55
|
methods.each do |method|
|
|
76
|
-
|
|
56
|
+
__define_singleton_method__(method, ::Object.instance_method(method).bind(self))
|
|
77
57
|
end
|
|
78
58
|
|
|
79
|
-
|
|
59
|
+
# If a block's provided, then `instance_exec`
|
|
60
|
+
__instance_exec__(&__any__ = block) if block
|
|
80
61
|
end
|
|
81
62
|
end
|
|
82
63
|
|
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
|
@@ -14,17 +14,17 @@ 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
21
|
|
|
22
22
|
# Creates a new {BlankValue}, and defining singleton methods depending on the parameters
|
|
23
23
|
#
|
|
24
24
|
# @param methods [Array[interned]] a list of {Object} methods to define on +self+.
|
|
25
25
|
# @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
|
|
26
26
|
# type can be used as a key in +Hash+es
|
|
27
|
-
# @yield [] if a block is given, runs it via +
|
|
27
|
+
# @yield [] if a block is given, runs it via +__instance_exec__+.
|
|
28
28
|
#
|
|
29
29
|
# === Example
|
|
30
30
|
# # Make a empty instance
|
|
@@ -38,25 +38,6 @@ module Blankity
|
|
|
38
38
|
#
|
|
39
39
|
# @rbs (?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
|
|
40
40
|
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
41
|
end
|
|
61
42
|
|
|
62
43
|
# Shorthand constructor {Blankity::Blank}.
|