blankity 0.0.2 → 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: 6c77ee6b4b3f72c8cfa617313fa1a70f14644c140dae8346fc77e8eeb6a9c7bf
4
- data.tar.gz: 6d612fe43c3cd9345f27947986a63fc980b2bb95c4f7f003a654fbd8a21c3bd5
3
+ metadata.gz: 2ac387131a2ec24c66cc4c22c214addbf73b0ab121350a39d4db6556fa78113c
4
+ data.tar.gz: 35a28db8ef6f0d040683c16e241897cc96ab4d0f0e754e6399cefd5d384a775f
5
5
  SHA512:
6
- metadata.gz: e267257370d73d2cd537e2d62da15694574ad00390d4385e487c95d9d4591a6ffd40eb5b14afd93209f222c3afb7356d326bb32988bbaaf9509b43b59ba7bcb2
7
- data.tar.gz: 56764266af70a160b088875284cfcfa168be5d8d5b1025f2445cafb4c98990affb137564fdaf4176a8a8819c9029acf934c78df176cdcdb03675233e07628402
6
+ metadata.gz: 9d189e2a9a0b63d7cd30636d7f0a645341fe8cf5fca106b2c1569f54ab15ef93984884014b69aa6bad0542669cf7c6eb9627a3d4d75a10d9bfa6b243a14179a1
7
+ data.tar.gz: 815454f7b361da955246a3f7119f8634b0e422563c3a41e5da22ae08c713c910dd7c017ee1879ce33070e4bb144957743da4293aedc8a8601dd3610f0e63c937
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --type-tag rbs --hide-tag rbs
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2025 SamW
3
+ Copyright (c) 2025 Sam Westerman
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "minitest/test_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'minitest/test_task'
5
5
 
6
6
  Minitest::TestTask.create
7
7
 
data/Steepfile CHANGED
@@ -4,10 +4,7 @@ target :lib do
4
4
  signature "sig"
5
5
  ignore_signature "sig/test"
6
6
 
7
- check "lib" # Directory name
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
@@ -21,12 +18,11 @@ target :lib do
21
18
  # end
22
19
  end
23
20
 
24
- # target :test do
21
+ target :test do
25
22
  # unreferenced! # Skip type checking the `lib` code when types in `test` target is changed
26
23
  # signature "sig/test" # Put RBS files for tests under `sig/test`
27
- # check "test" # Type check Ruby scripts under `test`
28
-
29
- # 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
30
28
 
31
- # # library "pathname" # Standard libraries
32
- # end
@@ -2,44 +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.
6
+ #
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}.
7
17
  class Blank < BasicObject
8
- # Remove every method except for `__send__` and `__id__`
18
+ # Remove every public and protected method that we inherit, except for `__xyz__` methods
9
19
  instance_methods.each do |name|
10
- undef_method(name) unless name == :__send__ || name == :__id__
20
+ undef_method(name) unless name.match?(/\A__.*__\z/)
11
21
  end
12
22
 
13
- # A helper method to define some `Kernel`methods on `self`
14
- def __with_Object_methods__(*methods)
15
- dsm = ::Object.instance_method(:define_singleton_method).bind(self)
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
16
27
 
17
- methods.each do |method|
18
- dsm.call(method, ::Object.instance_method(method))
19
- end
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
20
49
 
21
- self
22
- end
50
+ # Define any object methods requested by the end-user
51
+ __define_Object_methods__(*methods)
23
52
 
24
- # Same as `__with_Object_methods__`, but adds them to subclasses. This shouldn't
25
- # be called on `Blankity::Blank` directly, as that affects subclasses
26
- def self.__with_Object_methods__(*methods)
27
- if ::Blankity::Blank.equal?(self)
28
- raise ArgumentError, 'Cannot call `__with_Object_methods__` on Blank, as that will affect all blank slates'
29
- end
53
+ # If a block's provided, then `instance_exec`
54
+ INSTANCE_EXEC.bind_call(self, &__any__ = block) if block
55
+ end
30
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)
31
75
  methods.each do |method|
32
- define_method(method, ::Kernel.instance_method(method))
76
+ DEFINE_SINGLETON_METHOD.bind_call(self, method, ::Object.instance_method(method).bind(self))
33
77
  end
34
78
 
35
79
  self
36
80
  end
37
-
38
- # Helper method to create a new `Blank` with a block
39
- def self.blank(&block)
40
- ::Class.new(self, &block).new
41
- end
42
81
  end
43
82
 
44
- 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(...)
45
87
  end
@@ -2,162 +2,177 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
- class ValueBase < Blank
6
- 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
-
5
+ # Superclass of +ToXXX+ types
6
+ #
7
+ # @rbs generic T -- type of @__value__
8
+ class BlankValue < Blank
9
+ # @rbs @__value__: T
10
+
11
+ # Creates a new {BlankValue}, and defining singleton methods depending on the parameters
12
+ #
13
+ # @param value [T] the backing value for this class
14
+ # @param methods [Array[interned]] a list of {OBject} methods to define on +self+.
15
+ # @param hash [bool] convenience argument, adds +hash+ and +eql?+ to +methods+ so the resulting
16
+ # type can be used as a key in +Hash+es
17
+ # @yield [] if a block is given, runs it via +instance_exec+.
18
+ #
19
+ # @rbs (T, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
20
+ def initialize(value, ...)
10
21
  @__value__ = value
11
-
12
- ::Blankity.blank do
13
- # Always define the `to_method`
14
- define_singleton_method(:inspect) { to_method.to_s }
15
- define_method(to_method) { value }
16
-
17
- # For all the `methods` methods, fetch its definition from `value` and use that as the
18
- # definition
19
- methods.each do |method|
20
- define_method(method, &::Kernel.instance_method(:method).bind_call(value, method))
21
- end
22
-
23
- # If a block's given, execute it.
24
- class_exec(&block) if block
22
+ super(...)
25
23
  end
26
24
  end
27
25
 
28
- class ToI < Blank
29
- #: (Integer) -> void
30
- def initialize(value) = @__value__ = value
31
-
26
+ # A Class which exclusively defines +#to_i+; it implements RBS's +_ToI+ interface.
27
+ #
28
+ # @rbs inherits BlankValue[Integer]
29
+ class ToI < BlankValue
32
30
  #: () -> Integer
33
31
  def to_i = @__value__
34
32
  end
35
33
 
36
- class ToInt < Blank
37
- #: (Integer) -> void
38
- def initialize(value) = @__value__ = value
39
-
34
+ # A Class which exclusively defines +#to_int+; it implements RBS's +_ToInt+ interface.
35
+ #
36
+ # @rbs inherits BlankValue[Integer]
37
+ class ToInt < BlankValue
40
38
  #: () -> Integer
41
39
  def to_int = @__value__
42
40
  end
43
41
 
44
- class ToS < Blank
45
- #: (String) -> void
46
- def initialize(value) = @__value__ = value
47
-
42
+ # A Class which exclusively defines +#to_s+; it implements RBS's +_ToS+ interface.
43
+ #
44
+ # @rbs inherits BlankValue[String]
45
+ class ToS < BlankValue
48
46
  #: () -> String
49
47
  def to_s = @__value__
50
48
  end
51
49
 
52
- class ToStr < Blank
53
- #: (String) -> void
54
- def initialize(value) = @__value__ = value
55
-
50
+ # A Class which exclusively defines +#to_str+; it implements RBS's +_ToStr+ interface.
51
+ #
52
+ # @rbs inherits BlankValue[String]
53
+ class ToStr < BlankValue
56
54
  #: () -> String
57
55
  def to_str = @__value__
58
56
  end
59
57
 
58
+ # A Class which exclusively defines +#to_a+; it implements RBS's +_ToA[T]+ interface.
59
+ #
60
60
  # @rbs generic unchecked out T -- Type of elements
61
- class ToA < Blank
62
- #: (Array[T]) -> void
63
- def initialize(value) = @__value__ = value
64
-
61
+ # @rbs inherits BlankValue[Array[T]]
62
+ class ToA < BlankValue
65
63
  #: () -> Array[T]
66
64
  def to_a = @__value__
67
65
  end
68
66
 
67
+ # A Class which exclusively defines +#to_ary+; it implements RBS's +_ToAry[T]+ interface.
68
+ #
69
69
  # @rbs generic unchecked out T -- Type of elements
70
- class ToAry < Blank
71
- #: (Array[T]) -> void
72
- def initialize(value) = @__value__ = value
73
-
70
+ # @rbs inherits BlankValue[Array[T]]
71
+ class ToAry < BlankValue
74
72
  #: () -> Array[T]
75
73
  def to_ary = @__value__
76
74
  end
77
75
 
76
+ # A Class which exclusively defines +#to_h+; it implements RBS's +_ToH[K, V]+ interface.
77
+ #
78
78
  # @rbs generic unchecked out K -- Type of Key
79
79
  # @rbs generic unchecked out V -- Type of Value
80
- class ToH < Blank
81
- #: (Hash[K, V]) -> void
82
- def initialize(value) = @__value__ = value
83
-
80
+ # @rbs inherits BlankValue[Hash[K, V]]
81
+ class ToH < BlankValue
84
82
  #: () -> Hash[K, V]
85
83
  def to_h = @__value__
86
84
  end
87
85
 
86
+ # A Class which exclusively defines +#to_hash+; it implements RBS's +_ToHash[K, V]+ interface.
87
+ #
88
88
  # @rbs generic unchecked out K -- Type of Key
89
89
  # @rbs generic unchecked out V -- Type of Value
90
- class ToHash < Blank
91
- #: (Hash[K, V]) -> void
92
- def initialize(value) = @__value__ = value
93
-
90
+ # @rbs inherits BlankValue[Hash[K, V]]
91
+ class ToHash < BlankValue
94
92
  #: () -> Hash[K, V]
95
93
  def to_hash = @__value__
96
94
  end
97
95
 
98
- class ToSym < Blank
99
- #: (Symbol) -> void
100
- def initialize(value) = @__value__ = value
101
-
96
+ # A Class which exclusively defines +#to_sym+; it implements RBS's +_ToSym+ interface.
97
+ #
98
+ # @rbs inherits BlankValue[Symbol]
99
+ class ToSym < BlankValue
102
100
  #: () -> Symbol
103
101
  def to_sym = @__value__
104
102
  end
105
103
 
106
- class ToR < Blank
107
- #: (Rational) -> void
108
- def initialize(value) = @__value__ = value
109
-
104
+ # A Class which exclusively defines +#to_r+; it implements RBS's +_ToR+ interface.
105
+ #
106
+ # @rbs inherits BlankValue[Rational]
107
+ class ToR < BlankValue
110
108
  #: () -> Rational
111
109
  def to_r = @__value__
112
110
  end
113
111
 
114
- class ToC < Blank
115
- #: (Complex) -> void
116
- def initialize(value) = @__value__ = value
117
-
112
+ # A Class which exclusively defines +#to_c+; it implements RBS's +_ToC+ interface.
113
+ #
114
+ # @rbs inherits BlankValue[Complex]
115
+ class ToC < BlankValue
118
116
  #: () -> Complex
119
117
  def to_C = @__value__
120
118
  end
121
119
 
122
- class ToF < Blank
123
- #: (Float) -> void
124
- def initialize(value) = @__value__ = value
125
-
120
+ # A Class which exclusively defines +#to_f+; it implements RBS's +_ToF+ interface.
121
+ #
122
+ # @rbs inherits BlankValue[Float]
123
+ class ToF < BlankValue
126
124
  #: () -> Float
127
125
  def to_f = @__value__
128
126
  end
129
127
 
130
- class ToRegexp < Blank
131
- #: (Regexp) -> void
132
- def initialize(value) = @__value__ = value
133
-
128
+ # A Class which exclusively defines +#to_regexp+; it implements RBS's +Regexp::_ToRegexp+ interface.
129
+ #
130
+ # @rbs inherits BlankValue[Regexp]
131
+ class ToRegexp < BlankValue
134
132
  #: () -> Regexp
135
133
  def to_regexp = @__value__
136
134
  end
137
135
 
138
- class ToPath < Blank
139
- #: (String) -> void
140
- def initialize(value) = @__value__ = value
141
-
136
+ # A Class which exclusively defines +#to_path+; it implements RBS's +_ToPath+ interface.
137
+ #
138
+ # @rbs inherits BlankValue[String]
139
+ class ToPath < BlankValue
142
140
  #: () -> String
143
141
  def to_path = @__value__
144
142
  end
145
143
 
146
- class ToIO < Blank
147
- #: (IO) -> void
148
- def initialize(value) = @__value__ = value
149
-
144
+ # A Class which exclusively defines +#to_io+; it implements RBS's +_ToIO+ interface.
145
+ #
146
+ # @rbs inherits BlankValue[IO]
147
+ class ToIO < BlankValue
150
148
  #: () -> IO
151
149
  def to_io = @__value__
152
150
  end
153
151
 
152
+ # A Class which exclusively defines +#to_proc+; it implements RBS's +_ToProc+ interface.
153
+ #
154
+ # @rbs inherits BlankValue[Proc]
155
+ class ToProc < BlankValue
156
+ #: () -> Proc
157
+ def to_proc = @__value__
158
+ end
159
+
160
+ # A Class which defines `#begin`, `#end`, and `#exclude_end?`. It implements RBS's +_Range[T]+
161
+ # interface.
162
+ #
154
163
  # @rbs generic out T -- Type to iterate over
155
164
  class Range < Blank
156
- #: (T?, T?, ?bool) -> void
157
- def initialize(begin_, end_, exclude_end = false)
165
+ # @rbs @begin: T?
166
+ # @rbs @end: T?
167
+ # @rbs @exclude_end: bool
168
+
169
+ # @rbs (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: instance] -> void } -> void
170
+ def initialize(begin_, end_, exclude_end = false, ...)
158
171
  @__begin__ = begin_
159
172
  @__end__ = end_
160
173
  @__exclude_end__ = exclude_end
174
+
175
+ super(...)
161
176
  end
162
177
 
163
178
  #: () -> T?
@@ -167,6 +182,6 @@ module Blankity
167
182
  def end = @__end__
168
183
 
169
184
  #: () -> bool
170
- def exclude_end = @__exclude_end__
185
+ def exclude_end? = @__exclude_end__
171
186
  end
172
187
  end
data/lib/blankity/to.rb CHANGED
@@ -1,77 +1,50 @@
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
 
7
- # Helper method to create new `BlankSlate`s. Args:
8
- # - `to_method`: The method to use, eg `to_i`
9
- # - `value`: What to return when `to_method` is called
10
- # - `methods`: Optional list of methods from to define, using `value`'s definition
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
8
+ # @rbs (_ToI, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToI] -> void } -> ToI
9
+ def i(value, ...) = ToI.new(value.to_i, ...)
32
10
 
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
11
+ # @rbs (int, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToInt] -> void } -> ToInt
12
+ def int(value, ...) = ToInt.new(value.to_int, ...)
37
13
 
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
14
+ # @rbs (_ToS, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToS] -> void } -> ToS
15
+ def s(value, ...) = ToS.new(value.to_s, ...)
42
16
 
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
17
+ # @rbs (string, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToStr] -> void } -> ToStr
18
+ def str(value, ...) = ToStr.new(value.to_str, ...)
52
19
 
53
20
  # Create a type which _only_ responds to `.to_a`. See `to_helper` for details.
54
21
  #
55
22
  # This supports `a(1, 2, 3)` as a convenient shorthand for `a([1, 2, 3])`. To
56
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]
57
27
  def a(*elements, **, &)
58
- if elements.length == 1
59
- to_helper(:to_a, Array(elements[0]), **, &)
60
- else
61
- to_helper(:to_a, elements, **, &)
28
+ if elements.length == 1 && defined?(elements[0].to_a)
29
+ elements = (__any__ = elements[0]).to_a
62
30
  end
31
+
32
+ ToA.new(elements, **, &)
63
33
  end
64
34
 
65
35
  # Create a type which _only_ responds to `.to_ary`. See `to_helper` for details.
66
36
  #
67
37
  # This supports `ary(1, 2, 3)` as a convenient shorthand for `ary([1, 2, 3])`. To
68
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]
69
42
  def ary(*elements, **, &)
70
- if elements.length == 1
71
- to_helper(:to_ary, Array(elements[0]), **, &)
72
- else
73
- to_helper(:to_ary, elements, **, &)
43
+ if elements.length == 1 && defined?(elements[0].to_ary)
44
+ elements = (__any__ = elements[0]).to_ary
74
45
  end
46
+
47
+ ToAry.new(elements, **, &)
75
48
  end
76
49
 
77
50
  # Create a type which _only_ responds to `.to_h`. See `to_helper` for details.
@@ -79,11 +52,14 @@ module Blankity
79
52
  # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
80
53
  # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
81
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]
82
58
  def h(hash = nohash=true, **, &)
83
59
  if nohash
84
- to_helper(:to_h, {**}, &)
60
+ ToH.new({**}, &)
85
61
  else
86
- to_helper(:to_h, hash.to_h, **, &)
62
+ ToH.new(hash.to_h, **, &)
87
63
  end
88
64
  end
89
65
 
@@ -92,60 +68,60 @@ module Blankity
92
68
  # This supports passing in key/values directly via `h('a' => 'b')` as a convenient
93
69
  # shorthand for `h({'a' => 'b'})`, but the shorthand version doesn't allow you
94
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]
95
74
  def hash(hash = nohash=true, **, &)
96
75
  if nohash
97
- to_helper(:to_hash, {**}, &)
76
+ ToHash.new({**}, &)
98
77
  else
99
- to_helper(:to_hash, hash.to_hash, **, &)
78
+ ToHash.new((__any__ = hash).to_hash, **, &)
100
79
  end
101
80
  end
102
81
 
103
- # Create a type which _only_ responds to `.to_sym`. See `to_helper` for details.
104
- def sym(value, ...)
105
- to_helper(:to_sym, value.to_sym, ...)
106
- end
82
+ # @rbs (_ToSym, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToSym] -> void } -> ToSym
83
+ def sym(value, ...) = ToSym.new(value.to_sym, ...)
107
84
 
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
85
+ # @rbs (_ToR, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToR] -> void } -> ToR
86
+ def r(value, ...) = ToR.new(value.to_r, ...)
112
87
 
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
88
+ # @rbs (_ToC, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToC] -> void } -> ToC
89
+ def c(value, ...) = ToC.new(value.to_c, ...)
117
90
 
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
91
+ # @rbs (float, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToF] -> void } -> ToF
92
+ def f(value, ...) = ToF.new(value.to_f, ...)
122
93
 
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
94
+ # @rbs (Regexp::_ToRegexp, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToRegexp] -> void } -> ToRegexp
95
+ def regexp(value, ...) = ToRegexp.new(value.to_regexp, ...)
127
96
 
128
- # Create a type which _only_ responds to `.to_path`. See `to_helper` for details.
97
+ # @rbs (path, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToPath] -> void } -> ToPath
129
98
  def path(value, ...)
130
- to_helper(:to_path, defined?(value.to_path) ? value.to_path : String(value), ...)
99
+ ToPath.new(defined?(value.to_path) ? value.to_path : String(value), ...)
131
100
  end
132
101
 
133
- # Create a type which _only_ responds to `.to_io`. See `to_helper` for details.
134
- def io(value, ...)
135
- to_helper(:to_io, value.to_io, ...)
102
+ # @rbs (io, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToIO] -> void } -> ToIO
103
+ def io(value, ...) = ToIO.new(value.to_io, ...)
104
+
105
+ # @rbs (_ToProc, ?methods: Array[interned], ?hash: bool) ?{ () [self: ToProc] -> void } -> ToProc
106
+ def proc(proc = noproc=true, **, &block)
107
+ if noproc
108
+ unless block_given?
109
+ raise ArgumentError, 'if an explicit proc is omitted, a block must be passed'
110
+ end
111
+
112
+ ToProc.new(__any__ = block, **)
113
+ else
114
+ ToProc.new(proc.to_proc, **, &block)
115
+ end
136
116
  end
137
117
 
138
118
  # Create a type which _only_ responds to `.begin`, `.end`, and `.exclude_end?`
139
119
  # (the methods required to be considered a "custom range," eg for `Array#[]`.) See
140
120
  # `to_helper` for details.
141
- def range(begin_, end_, exclude_end = false, &)
142
- ::Blankity.blank do
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
121
+ #
122
+ # @rbs [T] (T?, T?, ?bool, ?methods: Array[interned], ?hash: bool) ?{ () [self: Range[T]] -> void } -> Range[T]
123
+ def range(begin_, end_, exclude_end = false, ...)
124
+ __any__ = Range.new(begin_, end_, exclude_end, ...)
149
125
  end
150
126
  end
151
127
  end
@@ -0,0 +1,23 @@
1
+ # rbs_inline: enabled
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
+ # We have to disable warnings for just this block, as Ruby warns for `undef`ing some methods
14
+ previous_warning, $-w = $-w, nil
15
+
16
+ (instance_methods + private_instance_methods).each do |name|
17
+ undef_method(name)
18
+ end
19
+
20
+ # Set warnings to what they used to be
21
+ $-w = previous_warning
22
+ end
23
+ end
@@ -2,5 +2,5 @@
2
2
  # rbs_inline: enabled
3
3
 
4
4
  module Blankity
5
- VERSION = '0.0.2'
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,20 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blankity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
- - SamW
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
- email:
13
- - mail@sampersand.me
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: []
17
19
  files:
20
+ - ".yardopts"
18
21
  - LICENSE.txt
19
22
  - README.md
20
23
  - Rakefile
@@ -23,16 +26,22 @@ files:
23
26
  - lib/blankity/blank.rb
24
27
  - lib/blankity/classes.rb
25
28
  - lib/blankity/to.rb
29
+ - lib/blankity/top.rb
26
30
  - lib/blankity/version.rb
27
31
  - sig/generated/blankity.rbs
28
32
  - sig/generated/blankity/blank.rbs
29
- - sig/generated/blankity/tos.rbs
33
+ - sig/generated/blankity/classes.rbs
34
+ - sig/generated/blankity/to.rbs
35
+ - sig/generated/blankity/top.rbs
30
36
  - sig/generated/blankity/version.rbs
31
- homepage: https://github.com/sampersand/blankity/blob/master
37
+ - sig/test/test/test_blank.rbs
38
+ - sig/test/test/test_helper.rbs
39
+ - sig/test/test/test_top.rbs
40
+ homepage: https://github.com/sampersand/blankity
32
41
  licenses:
33
42
  - MIT
34
43
  metadata:
35
- homepage_uri: https://github.com/sampersand/blankity/blob/master
44
+ homepage_uri: https://github.com/sampersand/blankity
36
45
  rdoc_options: []
37
46
  require_paths:
38
47
  - lib
@@ -40,7 +49,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
49
  requirements:
41
50
  - - ">="
42
51
  - !ruby/object:Gem::Version
43
- version: 3.1.0
52
+ version: 3.2.0
44
53
  required_rubygems_version: !ruby/object:Gem::Requirement
45
54
  requirements:
46
55
  - - ">="
@@ -49,5 +58,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
58
  requirements: []
50
59
  rubygems_version: 3.7.0.dev
51
60
  specification_version: 4
52
- summary: Helpers for creating types which _only_ respond to specific conversion methods
61
+ summary: Provides "blank" objects which *only* supply conversion methods
53
62
  test_files: []
@@ -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