blankity 0.1.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34a522794c85b7f50a815a2a17e455685e5fff40512134a8652d52705fd96946
4
- data.tar.gz: 44fe6ca43f7a274e076b00c83fee4da89617102769007615a56f9e8ba8345876
3
+ metadata.gz: 2ac387131a2ec24c66cc4c22c214addbf73b0ab121350a39d4db6556fa78113c
4
+ data.tar.gz: 35a28db8ef6f0d040683c16e241897cc96ab4d0f0e754e6399cefd5d384a775f
5
5
  SHA512:
6
- metadata.gz: 2679a4fc2901543f1df080226bcd8d41cde7fff84ffadf084a5a3b54509bc150e5e70ed9cc138624d3a9d9d0ba09f792b11ae7253894b9d35adab64a736c4eb3
7
- data.tar.gz: 9102b667417681d9e6c52a83d3e2742513d0ff9a95efaa5925f913c9017c0a841c14ea1d414b36846797d885568547f99feffb729de7e13d012bab88508301df
6
+ metadata.gz: 9d189e2a9a0b63d7cd30636d7f0a645341fe8cf5fca106b2c1569f54ab15ef93984884014b69aa6bad0542669cf7c6eb9627a3d4d75a10d9bfa6b243a14179a1
7
+ data.tar.gz: 815454f7b361da955246a3f7119f8634b0e422563c3a41e5da22ae08c713c910dd7c017ee1879ce33070e4bb144957743da4293aedc8a8601dd3610f0e63c937
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --type-tag rbs --hide-tag rbs
data/Steepfile CHANGED
@@ -18,12 +18,11 @@ target :lib do
18
18
  # end
19
19
  end
20
20
 
21
- # target :test do
21
+ target :test do
22
22
  # unreferenced! # Skip type checking the `lib` code when types in `test` target is changed
23
23
  # signature "sig/test" # Put RBS files for tests under `sig/test`
24
- # check "test" # Type check Ruby scripts under `test`
25
-
26
- # configure_code_diagnostics(D::Ruby.lenient) # Weak type checking for test code
24
+ check "test" # Type check Ruby scripts under `test`
25
+ configure_code_diagnostics(D::Ruby.lenient) # Weak type checking for test code
26
+ gem 'rake'
27
+ end
27
28
 
28
- # # library "pathname" # Standard libraries
29
- # end
@@ -2,54 +2,86 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
- # A "blank slate" class which removes _all_ methods (from `BasicObject`) other than the "required"
6
- # ones of `__send__` and `__id__`.
5
+ # An "emptier" class than {BasicObject}, which +undef+ines nearly all instance methods.
7
6
  #
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
+ # Not _all_ methods are undefined (see {AboslutelyBlank} for a class which does):
8
+ #
9
+ # - Methods which match +/\\A__.*__\\z/+ are not removed. Traditionally, these methods are expected
10
+ # to always be present (and +undef+ing them warns you!). Ruby has two of these: +__send__+
11
+ # and +__id__+
12
+ # - Private methods are not undefined, as each one of them is expected to be present (most of them
13
+ # are hooks, eg +singleton_method_added+), and aren't easily accessible from external classes.
14
+ #
15
+ # To make using +Blank+ easier, its constructor allows you to pass a +methods:+ keyword argument,
16
+ # which will define singleton methods based on {Object}.
10
17
  class Blank < BasicObject
11
- # Remove every method except for `__send__` and `__id__`
18
+ # Remove every public and protected method that we inherit, except for `__xyz__` methods
12
19
  instance_methods.each do |name|
13
- undef_method(name) unless name == :__send__ || name == :__id__
20
+ undef_method(name) unless name.match?(/\A__.*__\z/)
14
21
  end
15
22
 
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
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
22
27
 
23
- # A helper method to define some `Kernel`methods on `self`
24
- def __with_Object_methods__(*methods)
25
- dsm = ::Object.instance_method(:define_singleton_method).bind(self)
28
+ # Creates a new {BlankValue}, and defining singleton methods depending on the parameters
29
+ #
30
+ # @param methods [Array[interned]] a list of {Object} methods to define on +self+.
31
+ # @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
32
+ # type can be used as a key in +Hash+es
33
+ # @yield [] if a block is given, runs it via +instance_exec+.
34
+ #
35
+ # === Example
36
+ # # Make a empty instance
37
+ # Blankity::Blank.new
38
+ #
39
+ # # Include `Object#inspect`, so we can print with `p`
40
+ # p Blankity::Blank.new(methods: %i[inspect])
41
+ #
42
+ # # Define a singleton method
43
+ # p Blankity::Blank.new{ def cool?(other) = other == 3 }.cool?(3) #=> true
44
+ #
45
+ # @rbs (?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
46
+ def initialize(methods: [], hash: false, &block)
47
+ # If `hash` is supplied, then add `hash` and `eql?` to the list of methods to define
48
+ methods |= %i[hash eql?] if hash
26
49
 
27
- methods.each do |method|
28
- dsm.call(method, ::Object.instance_method(method))
29
- end
50
+ # Define any object methods requested by the end-user
51
+ __define_Object_methods__(*methods)
30
52
 
31
- self
53
+ # If a block's provided, then `instance_exec`
54
+ INSTANCE_EXEC.bind_call(self, &__any__ = block) if block
32
55
  end
33
56
 
34
- # Same as `__with_Object_methods__`, but adds them to subclasses. This shouldn't
35
- # be called on `Blankity::Blank` directly, as that affects subclasses
36
- def self.__with_Object_methods__(*methods)
37
- if ::Blankity::Blank.equal?(self)
38
- raise ArgumentError, 'Cannot call `__with_Object_methods__` on Blank, as that will affect all blank slates'
39
- end
40
-
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)
41
75
  methods.each do |method|
42
- define_method(method, ::Kernel.instance_method(method))
76
+ DEFINE_SINGLETON_METHOD.bind_call(self, method, ::Object.instance_method(method).bind(self))
43
77
  end
44
78
 
45
79
  self
46
80
  end
47
-
48
- # Helper method to create a new `Blank` with a block
49
- def self.blank(&block)
50
- ::Class.new(self, &block).new
51
- end
52
81
  end
53
82
 
54
- def self.blank(...) = Blank.blank(...)
83
+ # Shorthand constructor {Blankity::Blank}.
84
+ #
85
+ # @rbs (?methods: Array[interned], ?hash: bool) ?{ () [self: Blank] -> void } -> Blank
86
+ def self.blank(...) = Blank.new(...)
55
87
  end
@@ -2,39 +2,24 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
- # BlankValue is a superclass of the +ToXXX+ classes, which consolidates their initialization
6
- # into one convenient place
5
+ # Superclass of +ToXXX+ types
7
6
  #
8
7
  # @rbs generic T -- type of @__value__
9
8
  class BlankValue < Blank
10
9
  # @rbs @__value__: T
11
10
 
12
- DEFINE_SINGLETON_METHOD = ::Kernel.instance_method(:define_singleton_method)
13
- private_constant :DEFINE_SINGLETON_METHOD
14
-
15
11
  # Creates a new {BlankValue}, and defining singleton methods depending on the parameters
16
12
  #
17
13
  # @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>+
14
+ # @param methods [Array[interned]] a list of {OBject} methods to define on +self+.
20
15
  # @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
21
16
  # type can be used as a key in +Hash+es
22
17
  # @yield [] if a block is given, runs it via +instance_exec+.
23
18
  #
24
- # @rbs (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: self] -> void } -> void
25
- def initialize(value, methods: [], hash: false, &block)
19
+ # @rbs (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
20
+ def initialize(value, ...)
26
21
  @__value__ = value
27
-
28
- # If `hash` is supplied, then add `hash` and `eql?` to the list of methods to define
29
- methods |= %i[hash eql?] if hash
30
-
31
- methods.each do |method|
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))
35
- end
36
-
37
- instance_exec(&block) if block
22
+ super(...)
38
23
  end
39
24
  end
40
25
 
@@ -181,23 +166,13 @@ module Blankity
181
166
  # @rbs @end: T?
182
167
  # @rbs @exclude_end: bool
183
168
 
184
- #: (T?, T?, ?bool) -> void
185
- def initialize(begin_, end_, exclude_end = false, methods: [], hash: false, &block)
169
+ # @rbs (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
170
+ def initialize(begin_, end_, exclude_end = false, ...)
186
171
  @__begin__ = begin_
187
172
  @__end__ = end_
188
173
  @__exclude_end__ = exclude_end
189
174
 
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
175
+ super(...)
201
176
  end
202
177
 
203
178
  #: () -> T?
data/lib/blankity/to.rb CHANGED
@@ -1,21 +1,32 @@
1
1
  # frozen_string_literal: true
2
+ # rbs_inline: enabled
2
3
 
3
4
  module Blankity
4
5
  module To
5
6
  module_function
6
7
 
8
+ # @rbs (_ToI, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToI] -> void } -> ToI
7
9
  def i(value, ...) = ToI.new(value.to_i, ...)
10
+
11
+ # @rbs (int, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToInt] -> void } -> ToInt
8
12
  def int(value, ...) = ToInt.new(value.to_int, ...)
13
+
14
+ # @rbs (_ToS, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToS] -> void } -> ToS
9
15
  def s(value, ...) = ToS.new(value.to_s, ...)
16
+
17
+ # @rbs (string, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToStr] -> void } -> ToStr
10
18
  def str(value, ...) = ToStr.new(value.to_str, ...)
11
19
 
12
20
  # Create a type which _only_ responds to `.to_a`. See `to_helper` for details.
13
21
  #
14
22
  # This supports `a(1, 2, 3)` as a convenient shorthand for `a([1, 2, 3])`. To
15
23
  # create a `.to_a` that returns an array containing just an array, just use `a([array])`.
24
+ #
25
+ # @rbs [T] (_ToA[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
26
+ # | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
16
27
  def a(*elements, **, &)
17
28
  if elements.length == 1 && defined?(elements[0].to_a)
18
- elements = elements[0].to_a
29
+ elements = (__any__ = elements[0]).to_a
19
30
  end
20
31
 
21
32
  ToA.new(elements, **, &)
@@ -25,9 +36,12 @@ module Blankity
25
36
  #
26
37
  # This supports `ary(1, 2, 3)` as a convenient shorthand for `ary([1, 2, 3])`. To
27
38
  # create a `.to_ary` that returns an array containing just an array, use `ary([array])`.
39
+ #
40
+ # @rbs [T] (array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
41
+ # | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
28
42
  def ary(*elements, **, &)
29
43
  if elements.length == 1 && defined?(elements[0].to_ary)
30
- elements = elements[0].to_ary
44
+ elements = (__any__ = elements[0]).to_ary
31
45
  end
32
46
 
33
47
  ToAry.new(elements, **, &)
@@ -38,6 +52,9 @@ module Blankity
38
52
  # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
39
53
  # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
40
54
  # to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
55
+ #
56
+ # @rbs [K, V] (_ToH[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
57
+ # | [K, V] (**V) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
41
58
  def h(hash = nohash=true, **, &)
42
59
  if nohash
43
60
  ToH.new({**}, &)
@@ -51,32 +68,48 @@ module Blankity
51
68
  # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
52
69
  # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
53
70
  # to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
71
+ #
72
+ # @rbs [K, V] (hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
73
+ # | [K, V] (**V) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
54
74
  def hash(hash = nohash=true, **, &)
55
75
  if nohash
56
76
  ToHash.new({**}, &)
57
77
  else
58
- ToHash.new(hash.to_hash, **, &)
78
+ ToHash.new((__any__ = hash).to_hash, **, &)
59
79
  end
60
80
  end
61
81
 
82
+ # @rbs (_ToSym, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToSym] -> void } -> ToSym
62
83
  def sym(value, ...) = ToSym.new(value.to_sym, ...)
84
+
85
+ # @rbs (_ToR, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToR] -> void } -> ToR
63
86
  def r(value, ...) = ToR.new(value.to_r, ...)
87
+
88
+ # @rbs (_ToC, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToC] -> void } -> ToC
64
89
  def c(value, ...) = ToC.new(value.to_c, ...)
90
+
91
+ # @rbs (float, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToF] -> void } -> ToF
65
92
  def f(value, ...) = ToF.new(value.to_f, ...)
93
+
94
+ # @rbs (Regexp::_ToRegexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToRegexp] -> void } -> ToRegexp
66
95
  def regexp(value, ...) = ToRegexp.new(value.to_regexp, ...)
67
96
 
97
+ # @rbs (path, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToPath] -> void } -> ToPath
68
98
  def path(value, ...)
69
99
  ToPath.new(defined?(value.to_path) ? value.to_path : String(value), ...)
70
100
  end
71
101
 
102
+ # @rbs (io, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToIO] -> void } -> ToIO
72
103
  def io(value, ...) = ToIO.new(value.to_io, ...)
104
+
105
+ # @rbs (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
73
106
  def proc(proc = noproc=true, **, &block)
74
107
  if noproc
75
108
  unless block_given?
76
109
  raise ArgumentError, 'if an explicit proc is omitted, a block must be passed'
77
110
  end
78
111
 
79
- ToProc.new(block, **)
112
+ ToProc.new(__any__ = block, **)
80
113
  else
81
114
  ToProc.new(proc.to_proc, **, &block)
82
115
  end
@@ -85,8 +118,10 @@ module Blankity
85
118
  # Create a type which _only_ responds to `.begin`, `.end`, and `.exclude_end?`
86
119
  # (the methods required to be considered a "custom range," eg for `Array#[]`.) See
87
120
  # `to_helper` for details.
121
+ #
122
+ # @rbs [T] (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: Range[T]] -> void } -> Range[T]
88
123
  def range(begin_, end_, exclude_end = false, ...)
89
- Range.new(begin_, end_, exclude_end, ...)
124
+ __any__ = Range.new(begin_, end_, exclude_end, ...)
90
125
  end
91
126
  end
92
127
  end
@@ -1,3 +1,5 @@
1
+ # rbs_inline: enabled
2
+
1
3
  module Blankity
2
4
  # A Class that has _no_ instance methods on it whatsoever.
3
5
  #
@@ -6,8 +8,8 @@ module Blankity
6
8
  # builtin functionality. (For example, without +singleton_method_defined+, you can't actually
7
9
  # define singleton methods _at all_.)
8
10
  #
9
- # @see Blank for a type which doesn't undefine these critical builtin methods
10
- class AbsolutelyBlank < BasicObject
11
+ # @see Blank
12
+ class Top < BasicObject
11
13
  # We have to disable warnings for just this block, as Ruby warns for `undef`ing some methods
12
14
  previous_warning, $-w = $-w, nil
13
15
 
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
- VERSION = '0.1.0'
5
+ VERSION = '0.8.0'
6
6
  end
data/lib/blankity.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  module Blankity; end
5
5
 
6
6
  require_relative 'blankity/version'
7
+ require_relative 'blankity/top'
7
8
  require_relative 'blankity/blank'
8
9
  require_relative 'blankity/classes'
9
10
  require_relative 'blankity/to'
@@ -1,19 +1,66 @@
1
1
  # Generated from lib/blankity/blank.rb with RBS::Inline
2
2
 
3
3
  module Blankity
4
- # A "blank slate" class which removes _all_ methods (from `BasicObject`) other than the "required"
5
- # ones of `__send__` and `__id__`.
4
+ # An "emptier" class than {BasicObject}, which +undef+ines nearly all instance methods.
5
+ #
6
+ # Not _all_ methods are undefined (see {AboslutelyBlank} for a class which does):
7
+ #
8
+ # - Methods which match +/\\A__.*__\\z/+ are not removed. Traditionally, these methods are expected
9
+ # to always be present (and +undef+ing them warns you!). Ruby has two of these: +__send__+
10
+ # and +__id__+
11
+ # - Private methods are not undefined, as each one of them is expected to be present (most of them
12
+ # are hooks, eg +singleton_method_added+), and aren't easily accessible from external classes.
13
+ #
14
+ # To make using +Blank+ easier, its constructor allows you to pass a +methods:+ keyword argument,
15
+ # which will define singleton methods based on {Object}.
6
16
  class Blank < BasicObject
7
- # A helper method to define some `Kernel`methods on `self`
8
- def __with_Object_methods__: (*untyped methods) -> untyped
17
+ # Declare these as constants so we don't constantly look them up.
18
+ DEFINE_SINGLETON_METHOD: UnboundMethod
9
19
 
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
20
+ INSTANCE_EXEC: UnboundMethod
13
21
 
14
- # Helper method to create a new `Blank` with a block
15
- def self.blank: () ?{ (?) -> untyped } -> untyped
22
+ # Creates a new {BlankValue}, and defining singleton methods depending on the parameters
23
+ #
24
+ # @param methods [Array[interned]] a list of {Object} methods to define on +self+.
25
+ # @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
26
+ # type can be used as a key in +Hash+es
27
+ # @yield [] if a block is given, runs it via +instance_exec+.
28
+ #
29
+ # === Example
30
+ # # Make a empty instance
31
+ # Blankity::Blank.new
32
+ #
33
+ # # Include `Object#inspect`, so we can print with `p`
34
+ # p Blankity::Blank.new(methods: %i[inspect])
35
+ #
36
+ # # Define a singleton method
37
+ # p Blankity::Blank.new{ def cool?(other) = other == 3 }.cool?(3) #=> true
38
+ #
39
+ # @rbs (?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
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
16
60
  end
17
61
 
18
- def self.blank: () -> untyped
62
+ # Shorthand constructor {Blankity::Blank}.
63
+ #
64
+ # @rbs (?methods: Array[interned], ?hash: bool) ?{ () [self: Blank] -> void } -> Blank
65
+ def self.blank: (?methods: Array[interned], ?hash: bool) ?{ () [self: Blank] -> void } -> Blank
19
66
  end
@@ -0,0 +1,179 @@
1
+ # Generated from lib/blankity/classes.rb with RBS::Inline
2
+
3
+ module Blankity
4
+ # Superclass of +ToXXX+ types
5
+ #
6
+ # @rbs generic T -- type of @__value__
7
+ class BlankValue[T] < Blank
8
+ @__value__: T
9
+
10
+ # Creates a new {BlankValue}, and defining singleton methods depending on the parameters
11
+ #
12
+ # @param value [T] the backing value for this class
13
+ # @param methods [Array[interned]] a list of {OBject} methods to define on +self+.
14
+ # @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
15
+ # type can be used as a key in +Hash+es
16
+ # @yield [] if a block is given, runs it via +instance_exec+.
17
+ #
18
+ # @rbs (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
19
+ def initialize: (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
20
+ end
21
+
22
+ # A Class which exclusively defines +#to_i+; it implements RBS's +_ToI+ interface.
23
+ #
24
+ # @rbs inherits BlankValue[Integer]
25
+ class ToI < BlankValue[Integer]
26
+ # : () -> Integer
27
+ def to_i: () -> Integer
28
+ end
29
+
30
+ # A Class which exclusively defines +#to_int+; it implements RBS's +_ToInt+ interface.
31
+ #
32
+ # @rbs inherits BlankValue[Integer]
33
+ class ToInt < BlankValue[Integer]
34
+ # : () -> Integer
35
+ def to_int: () -> Integer
36
+ end
37
+
38
+ # A Class which exclusively defines +#to_s+; it implements RBS's +_ToS+ interface.
39
+ #
40
+ # @rbs inherits BlankValue[String]
41
+ class ToS < BlankValue[String]
42
+ # : () -> String
43
+ def to_s: () -> String
44
+ end
45
+
46
+ # A Class which exclusively defines +#to_str+; it implements RBS's +_ToStr+ interface.
47
+ #
48
+ # @rbs inherits BlankValue[String]
49
+ class ToStr < BlankValue[String]
50
+ # : () -> String
51
+ def to_str: () -> String
52
+ end
53
+
54
+ # A Class which exclusively defines +#to_a+; it implements RBS's +_ToA[T]+ interface.
55
+ #
56
+ # @rbs generic unchecked out T -- Type of elements
57
+ # @rbs inherits BlankValue[Array[T]]
58
+ class ToA[unchecked out T] < BlankValue[Array[T]]
59
+ # : () -> Array[T]
60
+ def to_a: () -> Array[T]
61
+ end
62
+
63
+ # A Class which exclusively defines +#to_ary+; it implements RBS's +_ToAry[T]+ interface.
64
+ #
65
+ # @rbs generic unchecked out T -- Type of elements
66
+ # @rbs inherits BlankValue[Array[T]]
67
+ class ToAry[unchecked out T] < BlankValue[Array[T]]
68
+ # : () -> Array[T]
69
+ def to_ary: () -> Array[T]
70
+ end
71
+
72
+ # A Class which exclusively defines +#to_h+; it implements RBS's +_ToH[K, V]+ interface.
73
+ #
74
+ # @rbs generic unchecked out K -- Type of Key
75
+ # @rbs generic unchecked out V -- Type of Value
76
+ # @rbs inherits BlankValue[Hash[K, V]]
77
+ class ToH[unchecked out K, unchecked out V] < BlankValue[Hash[K, V]]
78
+ # : () -> Hash[K, V]
79
+ def to_h: () -> Hash[K, V]
80
+ end
81
+
82
+ # A Class which exclusively defines +#to_hash+; it implements RBS's +_ToHash[K, V]+ interface.
83
+ #
84
+ # @rbs generic unchecked out K -- Type of Key
85
+ # @rbs generic unchecked out V -- Type of Value
86
+ # @rbs inherits BlankValue[Hash[K, V]]
87
+ class ToHash[unchecked out K, unchecked out V] < BlankValue[Hash[K, V]]
88
+ # : () -> Hash[K, V]
89
+ def to_hash: () -> Hash[K, V]
90
+ end
91
+
92
+ # A Class which exclusively defines +#to_sym+; it implements RBS's +_ToSym+ interface.
93
+ #
94
+ # @rbs inherits BlankValue[Symbol]
95
+ class ToSym < BlankValue[Symbol]
96
+ # : () -> Symbol
97
+ def to_sym: () -> Symbol
98
+ end
99
+
100
+ # A Class which exclusively defines +#to_r+; it implements RBS's +_ToR+ interface.
101
+ #
102
+ # @rbs inherits BlankValue[Rational]
103
+ class ToR < BlankValue[Rational]
104
+ # : () -> Rational
105
+ def to_r: () -> Rational
106
+ end
107
+
108
+ # A Class which exclusively defines +#to_c+; it implements RBS's +_ToC+ interface.
109
+ #
110
+ # @rbs inherits BlankValue[Complex]
111
+ class ToC < BlankValue[Complex]
112
+ # : () -> Complex
113
+ def to_C: () -> Complex
114
+ end
115
+
116
+ # A Class which exclusively defines +#to_f+; it implements RBS's +_ToF+ interface.
117
+ #
118
+ # @rbs inherits BlankValue[Float]
119
+ class ToF < BlankValue[Float]
120
+ # : () -> Float
121
+ def to_f: () -> Float
122
+ end
123
+
124
+ # A Class which exclusively defines +#to_regexp+; it implements RBS's +Regexp::_ToRegexp+ interface.
125
+ #
126
+ # @rbs inherits BlankValue[Regexp]
127
+ class ToRegexp < BlankValue[Regexp]
128
+ # : () -> Regexp
129
+ def to_regexp: () -> Regexp
130
+ end
131
+
132
+ # A Class which exclusively defines +#to_path+; it implements RBS's +_ToPath+ interface.
133
+ #
134
+ # @rbs inherits BlankValue[String]
135
+ class ToPath < BlankValue[String]
136
+ # : () -> String
137
+ def to_path: () -> String
138
+ end
139
+
140
+ # A Class which exclusively defines +#to_io+; it implements RBS's +_ToIO+ interface.
141
+ #
142
+ # @rbs inherits BlankValue[IO]
143
+ class ToIO < BlankValue[IO]
144
+ # : () -> IO
145
+ def to_io: () -> IO
146
+ end
147
+
148
+ # A Class which exclusively defines +#to_proc+; it implements RBS's +_ToProc+ interface.
149
+ #
150
+ # @rbs inherits BlankValue[Proc]
151
+ class ToProc < BlankValue[Proc]
152
+ # : () -> Proc
153
+ def to_proc: () -> Proc
154
+ end
155
+
156
+ # A Class which defines `#begin`, `#end`, and `#exclude_end?`. It implements RBS's +_Range[T]+
157
+ # interface.
158
+ #
159
+ # @rbs generic out T -- Type to iterate over
160
+ class Range[out T] < Blank
161
+ @begin: T?
162
+
163
+ @end: T?
164
+
165
+ @exclude_end: bool
166
+
167
+ # @rbs (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
168
+ def initialize: (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
169
+
170
+ # : () -> T?
171
+ def begin: () -> T?
172
+
173
+ # : () -> T?
174
+ def end: () -> T?
175
+
176
+ # : () -> bool
177
+ def exclude_end?: () -> bool
178
+ end
179
+ end
@@ -0,0 +1,90 @@
1
+ # Generated from lib/blankity/to.rb with RBS::Inline
2
+
3
+ module Blankity
4
+ module To
5
+ # @rbs (_ToI, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToI] -> void } -> ToI
6
+ def self?.i: (_ToI, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToI] -> void } -> ToI
7
+
8
+ # @rbs (int, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToInt] -> void } -> ToInt
9
+ def self?.int: (int, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToInt] -> void } -> ToInt
10
+
11
+ # @rbs (_ToS, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToS] -> void } -> ToS
12
+ def self?.s: (_ToS, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToS] -> void } -> ToS
13
+
14
+ # @rbs (string, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToStr] -> void } -> ToStr
15
+ def self?.str: (string, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToStr] -> void } -> ToStr
16
+
17
+ # Create a type which _only_ responds to `.to_a`. See `to_helper` for details.
18
+ #
19
+ # This supports `a(1, 2, 3)` as a convenient shorthand for `a([1, 2, 3])`. To
20
+ # create a `.to_a` that returns an array containing just an array, just use `a([array])`.
21
+ #
22
+ # @rbs [T] (_ToA[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
23
+ # | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
24
+ def self?.a: [T] (_ToA[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
25
+ | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToA[T]] -> void } -> ToA[T]
26
+
27
+ # Create a type which _only_ responds to `.to_ary`. See `to_helper` for details.
28
+ #
29
+ # This supports `ary(1, 2, 3)` as a convenient shorthand for `ary([1, 2, 3])`. To
30
+ # create a `.to_ary` that returns an array containing just an array, use `ary([array])`.
31
+ #
32
+ # @rbs [T] (array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
33
+ # | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
34
+ def self?.ary: [T] (array[T], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
35
+ | [T] (*T, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToAry[T]] -> void } -> ToAry[T]
36
+
37
+ # Create a type which _only_ responds to `.to_h`. See `to_helper` for details.
38
+ #
39
+ # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
40
+ # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
41
+ # to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
42
+ #
43
+ # @rbs [K, V] (_ToH[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
44
+ # | [K, V] (**V) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
45
+ def self?.h: [K, V] (_ToH[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
46
+ | [K, V] (**V) ?{ () [self: ToH[K, V]] -> void } -> ToH[K, V]
47
+
48
+ # Create a type which _only_ responds to `.to_hash`. See `to_helper` for details.
49
+ #
50
+ # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
51
+ # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
52
+ # to supply keyowrd arguments that `to_helper` expects. Use `h({'a' => 'b'}, ...)` for that.
53
+ #
54
+ # @rbs [K, V] (hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
55
+ # | [K, V] (**V) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
56
+ def self?.hash: [K, V] (hash[K, V], ?methods: Array[interned], ?hash: bool) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
57
+ | [K, V] (**V) ?{ () [self: ToHash[K, V]] -> void } -> ToHash[K, V]
58
+
59
+ # @rbs (_ToSym, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToSym] -> void } -> ToSym
60
+ def self?.sym: (_ToSym, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToSym] -> void } -> ToSym
61
+
62
+ # @rbs (_ToR, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToR] -> void } -> ToR
63
+ def self?.r: (_ToR, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToR] -> void } -> ToR
64
+
65
+ # @rbs (_ToC, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToC] -> void } -> ToC
66
+ def self?.c: (_ToC, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToC] -> void } -> ToC
67
+
68
+ # @rbs (float, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToF] -> void } -> ToF
69
+ def self?.f: (float, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToF] -> void } -> ToF
70
+
71
+ # @rbs (Regexp::_ToRegexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToRegexp] -> void } -> ToRegexp
72
+ def self?.regexp: (Regexp::_ToRegexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToRegexp] -> void } -> ToRegexp
73
+
74
+ # @rbs (path, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToPath] -> void } -> ToPath
75
+ def self?.path: (path, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToPath] -> void } -> ToPath
76
+
77
+ # @rbs (io, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToIO] -> void } -> ToIO
78
+ def self?.io: (io, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToIO] -> void } -> ToIO
79
+
80
+ # @rbs (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
81
+ def self?.proc: (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
82
+
83
+ # Create a type which _only_ responds to `.begin`, `.end`, and `.exclude_end?`
84
+ # (the methods required to be considered a "custom range," eg for `Array#[]`.) See
85
+ # `to_helper` for details.
86
+ #
87
+ # @rbs [T] (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: Range[T]] -> void } -> Range[T]
88
+ def self?.range: [T] (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: Range[T]] -> void } -> Range[T]
89
+ end
90
+ end
@@ -0,0 +1,14 @@
1
+ # Generated from lib/blankity/top.rb with RBS::Inline
2
+
3
+ module Blankity
4
+ # A Class that has _no_ instance methods on it whatsoever.
5
+ #
6
+ # This is actually pretty difficult to use properly, as some methods (e.g. +initialize+
7
+ # and +singleton_method_defined+) are expected by Ruby to always exist, and restrict a lot of
8
+ # builtin functionality. (For example, without +singleton_method_defined+, you can't actually
9
+ # define singleton methods _at all_.)
10
+ #
11
+ # @see Blank
12
+ class Top < BasicObject
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ class TestBlankity_Top < Minitest::Test
2
+ def test_that_it_doesnt_undef_private_methods: () -> untyped
3
+
4
+ def test_that_it_only_has_underscore_methods: () -> untyped
5
+
6
+ def assert_singleton_methods: (untyped methods, untyped instance) -> untyped
7
+
8
+ def test_initialize_with_argouments: () -> untyped
9
+
10
+ def test_initialize_with_methods: () -> untyped
11
+
12
+ def test_initialize_with_hash: () -> untyped
13
+
14
+ def test_initialize_with_methods_and_hash: () -> untyped
15
+
16
+ def test_initialize_with_block: () -> untyped
17
+
18
+ def test_initialize_with_block_is_run_after_methods: () -> untyped
19
+
20
+ def test___define_Object_methods__: () -> untyped
21
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ class TestBlankity_Top < Minitest::Test
2
+ def test_it_has_no_instance_methods: () -> untyped
3
+ 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.1.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Westerman
@@ -17,20 +17,26 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".yardopts"
20
21
  - LICENSE.txt
21
22
  - README.md
22
23
  - Rakefile
23
24
  - Steepfile
24
25
  - lib/blankity.rb
25
- - lib/blankity/absolutely_blank.rb
26
26
  - lib/blankity/blank.rb
27
27
  - lib/blankity/classes.rb
28
28
  - lib/blankity/to.rb
29
+ - lib/blankity/top.rb
29
30
  - lib/blankity/version.rb
30
31
  - sig/generated/blankity.rbs
31
32
  - sig/generated/blankity/blank.rbs
32
- - sig/generated/blankity/tos.rbs
33
+ - sig/generated/blankity/classes.rbs
34
+ - sig/generated/blankity/to.rbs
35
+ - sig/generated/blankity/top.rbs
33
36
  - sig/generated/blankity/version.rbs
37
+ - sig/test/test/test_blank.rbs
38
+ - sig/test/test/test_helper.rbs
39
+ - sig/test/test/test_top.rbs
34
40
  homepage: https://github.com/sampersand/blankity
35
41
  licenses:
36
42
  - MIT
@@ -1,44 +0,0 @@
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