ruby_arguments 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/ruby_arguments/version.rb +6 -1
- data/lib/ruby_arguments.rb +66 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 797ac853f48f6fff8bf279034396df2871e32a8262a61bb4fe2dcc48a18470c4
|
|
4
|
+
data.tar.gz: f915acf7426c33d210252862f78f6122e4f6c33a02b2d10d21b0eaed1bab28e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 00bc1e115f3170671790ae88af6ed09faf660f860264140a752087219e8ec29243b2f870d3139224e3ed246a90a9ab16e52d241f77b1c545dac271b53c2f98b9
|
|
7
|
+
data.tar.gz: 8a90564da79c936954d46b51199bfbf16deb15e09166cb3c9d26d664e832c610f591923c8746ddc83bed8d7961a3b829dc215f795e115cbf7e5101a0317e3b6f
|
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://rubygems.org/gems/ruby_arguments) [](https://rubygems.org/gems/ruby_arguments)  [](https://github.com/marian13/ruby_arguments/actions/workflows/ci.yml) [](https://github.com/testdouble/standard) [](https://coveralls.io/github/marian13/ruby_arguments?branch=main) [](https://marian13.github.io/ruby_arguments)
|
|
9
9
|
[](https://opensource.org/licenses/MIT)
|
|
10
10
|
|
|
11
|
-
Ruby Arguments encapsulate method positional arguments (`args`), keyword arguments (`kwargs`), and an optional block (`block`) in a single value object (null object is also available).
|
|
11
|
+
Ruby Arguments encapsulate method positional arguments (`args`), keyword arguments (`kwargs`), and an optional block (`block`) in a single value object ([null object](https://refactoring.guru/introduce-null-object) is also available).
|
|
12
12
|
|
|
13
13
|
That may be useful for DSLs, caches, callbacks, custom RSpec matchers, hash keys, pattern matching and so on.
|
|
14
14
|
|
|
@@ -45,7 +45,7 @@ arguments.kwargs
|
|
|
45
45
|
arguments.block
|
|
46
46
|
# => #<Proc:0x000000012a97fc18>
|
|
47
47
|
|
|
48
|
-
arguments.null_arguments?
|
|
48
|
+
arguments.null_arguments? # Or an alias `arguments.nil_arguments?`.
|
|
49
49
|
# => false
|
|
50
50
|
|
|
51
51
|
arguments.any?
|
|
@@ -117,4 +117,4 @@ gem install ruby_arguments
|
|
|
117
117
|
|
|
118
118
|
---
|
|
119
119
|
|
|
120
|
-
Copyright (c) 2025 Marian Kostyk.
|
|
120
|
+
Copyright (c) 2025-2026 Marian Kostyk.
|
data/lib/ruby_arguments.rb
CHANGED
|
@@ -5,11 +5,25 @@
|
|
|
5
5
|
# @license MIT <https://opensource.org/license/mit>
|
|
6
6
|
##
|
|
7
7
|
|
|
8
|
+
require_relative "ruby_arguments/version"
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
# @api public
|
|
12
|
+
# @since 1.0.0
|
|
13
|
+
#
|
|
8
14
|
class RubyArguments
|
|
9
15
|
module Exceptions
|
|
16
|
+
##
|
|
17
|
+
# @api public
|
|
18
|
+
# @since 1.0.0
|
|
19
|
+
#
|
|
10
20
|
class Base < ::StandardError
|
|
11
21
|
end
|
|
12
22
|
|
|
23
|
+
##
|
|
24
|
+
# @api public
|
|
25
|
+
# @since 1.0.0
|
|
26
|
+
#
|
|
13
27
|
class InvalidKeyType < Base
|
|
14
28
|
class << self
|
|
15
29
|
##
|
|
@@ -30,6 +44,10 @@ class RubyArguments
|
|
|
30
44
|
end
|
|
31
45
|
end
|
|
32
46
|
|
|
47
|
+
##
|
|
48
|
+
# @api public
|
|
49
|
+
# @since 1.0.0
|
|
50
|
+
#
|
|
33
51
|
class NullArguments < ::RubyArguments
|
|
34
52
|
##
|
|
35
53
|
# @api private
|
|
@@ -43,15 +61,27 @@ class RubyArguments
|
|
|
43
61
|
|
|
44
62
|
##
|
|
45
63
|
# @api public
|
|
64
|
+
# @since 1.0.0
|
|
46
65
|
# @return [Boolean]
|
|
47
66
|
#
|
|
48
67
|
def null_arguments?
|
|
49
68
|
true
|
|
50
69
|
end
|
|
70
|
+
|
|
71
|
+
##
|
|
72
|
+
# @api public
|
|
73
|
+
# @since 1.1.0
|
|
74
|
+
# @return [Boolean]
|
|
75
|
+
#
|
|
76
|
+
# @note Original pattern is called Null Object. Since Ruby has `nil` instead of `null` this alias is introduced.
|
|
77
|
+
# @see https://refactoring.guru/introduce-null-object
|
|
78
|
+
#
|
|
79
|
+
alias_method :nil_arguments?, :null_arguments?
|
|
51
80
|
end
|
|
52
81
|
|
|
53
82
|
##
|
|
54
83
|
# @api public
|
|
84
|
+
# @since 1.0.0
|
|
55
85
|
# @!attribute [r] args
|
|
56
86
|
# @return [Array<Object>]
|
|
57
87
|
#
|
|
@@ -59,6 +89,7 @@ class RubyArguments
|
|
|
59
89
|
|
|
60
90
|
##
|
|
61
91
|
# @api public
|
|
92
|
+
# @since 1.0.0
|
|
62
93
|
# @!attribute [r] kwargs
|
|
63
94
|
# @return [Hash{Symbol => Object}]
|
|
64
95
|
#
|
|
@@ -66,6 +97,7 @@ class RubyArguments
|
|
|
66
97
|
|
|
67
98
|
##
|
|
68
99
|
# @api public
|
|
100
|
+
# @since 1.0.0
|
|
69
101
|
# @!attribute [r] block
|
|
70
102
|
# @return [Proc, nil]
|
|
71
103
|
#
|
|
@@ -73,6 +105,7 @@ class RubyArguments
|
|
|
73
105
|
|
|
74
106
|
##
|
|
75
107
|
# @api public
|
|
108
|
+
# @since 1.0.0
|
|
76
109
|
# @param args [Array<Object>]
|
|
77
110
|
# @param kwargs [Hash{Symbol => Object}]
|
|
78
111
|
# @param block [Proc, nil]
|
|
@@ -87,15 +120,27 @@ class RubyArguments
|
|
|
87
120
|
class << self
|
|
88
121
|
##
|
|
89
122
|
# @api public
|
|
123
|
+
# @since 1.0.0
|
|
90
124
|
# @return [RubyArguments::NullArguments]
|
|
91
125
|
#
|
|
92
126
|
def null_arguments
|
|
93
127
|
@null_arguments ||= ::RubyArguments::NullArguments.new
|
|
94
128
|
end
|
|
129
|
+
|
|
130
|
+
##
|
|
131
|
+
# @api public
|
|
132
|
+
# @since 1.1.0
|
|
133
|
+
# @return [RubyArguments::NullArguments]
|
|
134
|
+
#
|
|
135
|
+
# @note Original pattern is called Null Object. Since Ruby has `nil` instead of `null` this alias is introduced.
|
|
136
|
+
# @see https://refactoring.guru/introduce-null-object
|
|
137
|
+
#
|
|
138
|
+
alias_method :nil_arguments, :null_arguments
|
|
95
139
|
end
|
|
96
140
|
|
|
97
141
|
##
|
|
98
142
|
# @api public
|
|
143
|
+
# @since 1.0.0
|
|
99
144
|
# @return [Boolean]
|
|
100
145
|
#
|
|
101
146
|
def null_arguments?
|
|
@@ -104,6 +149,17 @@ class RubyArguments
|
|
|
104
149
|
|
|
105
150
|
##
|
|
106
151
|
# @api public
|
|
152
|
+
# @since 1.1.0
|
|
153
|
+
# @return [Boolean]
|
|
154
|
+
#
|
|
155
|
+
# @note Original pattern is called Null Object. Since Ruby has `nil` instead of `null` this alias is introduced.
|
|
156
|
+
# @see https://refactoring.guru/introduce-null-object
|
|
157
|
+
#
|
|
158
|
+
alias_method :nil_arguments?, :null_arguments?
|
|
159
|
+
|
|
160
|
+
##
|
|
161
|
+
# @api public
|
|
162
|
+
# @since 1.0.0
|
|
107
163
|
# @return [Booleam]
|
|
108
164
|
#
|
|
109
165
|
def any?
|
|
@@ -116,6 +172,7 @@ class RubyArguments
|
|
|
116
172
|
|
|
117
173
|
##
|
|
118
174
|
# @api public
|
|
175
|
+
# @since 1.0.0
|
|
119
176
|
# @return [Booleam]
|
|
120
177
|
#
|
|
121
178
|
def none?
|
|
@@ -124,6 +181,7 @@ class RubyArguments
|
|
|
124
181
|
|
|
125
182
|
##
|
|
126
183
|
# @api public
|
|
184
|
+
# @since 1.0.0
|
|
127
185
|
# @return [Booleam]
|
|
128
186
|
#
|
|
129
187
|
def empty?
|
|
@@ -132,6 +190,7 @@ class RubyArguments
|
|
|
132
190
|
|
|
133
191
|
##
|
|
134
192
|
# @api public
|
|
193
|
+
# @since 1.0.0
|
|
135
194
|
# @return [Booleam]
|
|
136
195
|
#
|
|
137
196
|
def present?
|
|
@@ -140,6 +199,7 @@ class RubyArguments
|
|
|
140
199
|
|
|
141
200
|
##
|
|
142
201
|
# @api public
|
|
202
|
+
# @since 1.0.0
|
|
143
203
|
# @return [Booleam]
|
|
144
204
|
#
|
|
145
205
|
def blank?
|
|
@@ -148,6 +208,7 @@ class RubyArguments
|
|
|
148
208
|
|
|
149
209
|
##
|
|
150
210
|
# @api public
|
|
211
|
+
# @since 1.0.0
|
|
151
212
|
# @param key [Integer, Symbol]
|
|
152
213
|
# @return [Object] Can be any type.
|
|
153
214
|
# @raise [RubyArguments::Exceptions::InvalidKeyType]
|
|
@@ -162,6 +223,7 @@ class RubyArguments
|
|
|
162
223
|
|
|
163
224
|
##
|
|
164
225
|
# @api public
|
|
226
|
+
# @since 1.0.0
|
|
165
227
|
# @param other [Object] Can be any type.
|
|
166
228
|
# @return [Boolean, nil]
|
|
167
229
|
#
|
|
@@ -177,6 +239,7 @@ class RubyArguments
|
|
|
177
239
|
|
|
178
240
|
##
|
|
179
241
|
# @api public
|
|
242
|
+
# @since 1.0.0
|
|
180
243
|
# @param other [Object] Can be any type.
|
|
181
244
|
# @return [Boolean, nil]
|
|
182
245
|
#
|
|
@@ -192,6 +255,7 @@ class RubyArguments
|
|
|
192
255
|
|
|
193
256
|
##
|
|
194
257
|
# @api public
|
|
258
|
+
# @since 1.0.0
|
|
195
259
|
# @return [Integer]
|
|
196
260
|
#
|
|
197
261
|
def hash
|
|
@@ -200,6 +264,7 @@ class RubyArguments
|
|
|
200
264
|
|
|
201
265
|
##
|
|
202
266
|
# @api public
|
|
267
|
+
# @since 1.0.0
|
|
203
268
|
# @return [Array]
|
|
204
269
|
#
|
|
205
270
|
def deconstruct
|
|
@@ -208,6 +273,7 @@ class RubyArguments
|
|
|
208
273
|
|
|
209
274
|
##
|
|
210
275
|
# @api public
|
|
276
|
+
# @since 1.0.0
|
|
211
277
|
# @param keys [Array<Symbol>, nil]
|
|
212
278
|
# @return [Hash]
|
|
213
279
|
#
|