blankity 0.9.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 96f50e260e8b3b183ecc3d40988238c571021514c813ae3e0032f76cf35744ac
4
- data.tar.gz: fa48b5c00198840392e473b1cdd0904f96303bb4d52c6e81adc30355fec42d75
3
+ metadata.gz: 0a2474babea0e68bddb79670ae6b5680fd0b2be07677b502071d2d9a1abf4eea
4
+ data.tar.gz: 6898a094071b9dfa0bd62863ee9b64cf5823c664d84a77913597c999826e92e8
5
5
  SHA512:
6
- metadata.gz: 3f4a1f1a834cc6b410cc9b27b805a62ed2bc3a9a9788669206e07f395e5e583db23c9541ca585ab982b4b94d5c051595b196b30692dea593b2ab6d5a5ed34e77
7
- data.tar.gz: 92bfb06c6c8011f39f0d7bbf68d091df456ee43767c6f579bd912b03f3e5221e9071ff83dbc83bd8d1ae9cb3aa925e4a42ec267ff4ba28ff61fe06d902963afb
6
+ metadata.gz: b0ff3504d136935da61af9c623b4e09a6765c5cb865ce97ee0ef31d82f44b9355109c221ec68432e7c0a0d26db1ed56ca54066e9a2f40ee8fead43a3e1aec222
7
+ data.tar.gz: 98067d34173efe13142af36e399ee04ed95905924e4727995c1b0f09ded1cf679979fdca7b3718fbf03dffb574b6b6ff1e7f440b95cc2ce19b2fbc1ce0f6915f
@@ -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
- # Remove every public and protected method that we inherit, except for `__xyz__` methods
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 +instance_exec+.
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
- DEFINE_SINGLETON_METHOD.bind_call(self, method, ::Object.instance_method(method).bind(self))
56
+ __define_singleton_method__(method, ::Object.instance_method(method).bind(self))
77
57
  end
78
58
 
79
- self
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
@@ -2,7 +2,27 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
+ # Convenience methods for creating new +BlankIty::ToXXX+ instances.
6
+ #
7
+ # Using +To+ as a mixin (via +extend+ / +include+ / +prepend+) isn't suggested, as {Kernel#proc}
8
+ # and {Kernel#hash} will be overwritten. Attempting to do so will emit a warning if `$VERBOSE` is
9
+ # enabled.
5
10
  module To
11
+ # Warn when including +To+
12
+ def self.included(mod)
13
+ $VERBOSE and warn 'including Blankity::To overwrites Kernel#proc and Kernel#hash', uplevel: 1
14
+ end
15
+
16
+ # Warn when extending +To+
17
+ def self.extended(mod)
18
+ $VERBOSE and warn 'extending Blankity::To overwrites Kernel#proc and Kernel#hash', uplevel: 1
19
+ end
20
+
21
+ # Warn when prepending +To+
22
+ def self.prepended(mod)
23
+ $VERBOSE and warn 'prepending Blankity::To overwrites Kernel#proc and Kernel#hash', uplevel: 1
24
+ end
25
+
6
26
  module_function
7
27
 
8
28
  # Convenience method to make {ToI}s from +value.to_i+
@@ -111,7 +131,7 @@ module Blankity
111
131
  #
112
132
  # @rbs (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
113
133
  # | (?methods: Array[interned], ?hash: bool) { (?) -> untyped } -> ToProc
114
- def proc(proc = nil, **, &block)
134
+ def self.proc(proc = nil, **, &block)
115
135
  if proc
116
136
  ToProc.new(proc.to_proc, **, &block)
117
137
  elsif !block_given?
@@ -129,3 +149,4 @@ module Blankity
129
149
  end
130
150
  end
131
151
  end
152
+
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
- VERSION = '0.9.1'
5
+ VERSION = '0.9.3'
6
6
  end
@@ -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
- # Declare these as constants so we don't constantly look them up.
18
- DEFINE_SINGLETON_METHOD: UnboundMethod
17
+ def __define_singleton_method__: (interned name, Method | UnboundMethod | Proc method) -> Symbol
18
+ | (interned name) { (?) [self: self] -> untyped } -> Symbol
19
19
 
20
- INSTANCE_EXEC: UnboundMethod
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 +instance_exec+.
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}.
@@ -1,7 +1,21 @@
1
1
  # Generated from lib/blankity/to.rb with RBS::Inline
2
2
 
3
3
  module Blankity
4
+ # Convenience methods for creating new +BlankIty::ToXXX+ instances.
5
+ #
6
+ # Using +To+ as a mixin (via +extend+ / +include+ / +prepend+) isn't suggested, as {Kernel#proc}
7
+ # and {Kernel#hash} will be overwritten. Attempting to do so will emit a warning if `$VERBOSE` is
8
+ # enabled.
4
9
  module To
10
+ # Warn when including +To+
11
+ def self.included: (untyped mod) -> untyped
12
+
13
+ # Warn when extending +To+
14
+ def self.extended: (untyped mod) -> untyped
15
+
16
+ # Warn when prepending +To+
17
+ def self.prepended: (untyped mod) -> untyped
18
+
5
19
  # Convenience method to make {ToI}s from +value.to_i+
6
20
  #
7
21
  # @rbs (_ToI, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToI] -> void } -> ToI
@@ -16,6 +16,4 @@ class TestBlankity_Top < Minitest::Test
16
16
  def test_initialize_with_block: () -> untyped
17
17
 
18
18
  def test_initialize_with_block_is_run_after_methods: () -> untyped
19
-
20
- def test___define_Object_methods__: () -> untyped
21
19
  end
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.9.1
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Westerman