others 0.0.3 → 0.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/.0pdd.yml +2 -19
- data/.github/workflows/actionlint.yml +5 -21
- data/.github/workflows/codecov.yml +9 -23
- data/.github/workflows/copyrights.yml +6 -21
- data/.github/workflows/markdown-lint.yml +6 -21
- data/.github/workflows/pdd.yml +5 -20
- data/.github/workflows/rake.yml +7 -23
- data/.github/workflows/reuse.yml +19 -0
- data/.github/workflows/typos.yml +19 -0
- data/.github/workflows/xcop.yml +5 -20
- data/.github/workflows/yamllint.yml +5 -20
- data/.gitignore +7 -5
- data/.rubocop.yml +7 -20
- data/.rultor.yml +4 -20
- data/.yamllint.yml +2 -19
- data/Gemfile +12 -28
- data/Gemfile.lock +57 -143
- data/LICENSE.txt +1 -1
- data/LICENSES/MIT.txt +21 -0
- data/README.md +25 -7
- data/REUSE.toml +34 -0
- data/Rakefile +3 -29
- data/lib/others.rb +65 -25
- data/others.gemspec +3 -20
- data/test/test__helper.rb +22 -22
- data/test/test_others.rb +22 -21
- metadata +8 -8
- data/.simplecov +0 -41
data/Gemfile.lock
CHANGED
@@ -6,138 +6,54 @@ PATH
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
activesupport (= 7.1.3.4)
|
12
|
-
nokogiri (>= 1.8.5)
|
13
|
-
racc
|
14
|
-
rack (>= 2.2.4)
|
15
|
-
rack-session (>= 1.0.1)
|
16
|
-
rack-test (>= 0.6.3)
|
17
|
-
rails-dom-testing (~> 2.2)
|
18
|
-
rails-html-sanitizer (~> 1.6)
|
19
|
-
actionview (7.1.3.4)
|
20
|
-
activesupport (= 7.1.3.4)
|
21
|
-
builder (~> 3.1)
|
22
|
-
erubi (~> 1.11)
|
23
|
-
rails-dom-testing (~> 2.2)
|
24
|
-
rails-html-sanitizer (~> 1.6)
|
25
|
-
activesupport (7.1.3.4)
|
26
|
-
base64
|
27
|
-
bigdecimal
|
28
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
29
|
-
connection_pool (>= 2.2.5)
|
30
|
-
drb
|
31
|
-
i18n (>= 1.6, < 2)
|
32
|
-
minitest (>= 5.1)
|
33
|
-
mutex_m
|
34
|
-
tzinfo (~> 2.0)
|
35
|
-
ast (2.4.2)
|
36
|
-
base64 (0.2.0)
|
37
|
-
bigdecimal (3.1.8)
|
9
|
+
ansi (1.5.0)
|
10
|
+
ast (2.4.3)
|
38
11
|
builder (3.3.0)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
reline (>= 0.4.2)
|
52
|
-
json (2.7.2)
|
53
|
-
language_server-protocol (3.17.0.3)
|
54
|
-
loofah (2.22.0)
|
55
|
-
crass (~> 1.0.2)
|
56
|
-
nokogiri (>= 1.12.0)
|
57
|
-
minitest (5.24.0)
|
58
|
-
mutex_m (0.2.0)
|
59
|
-
nokogiri (1.16.6-arm64-darwin)
|
60
|
-
racc (~> 1.4)
|
61
|
-
nokogiri (1.16.6-x64-mingw-ucrt)
|
62
|
-
racc (~> 1.4)
|
63
|
-
nokogiri (1.16.6-x86_64-darwin)
|
64
|
-
racc (~> 1.4)
|
65
|
-
nokogiri (1.16.6-x86_64-linux)
|
66
|
-
racc (~> 1.4)
|
67
|
-
parallel (1.25.1)
|
68
|
-
parser (3.3.3.0)
|
12
|
+
docile (1.4.1)
|
13
|
+
json (2.12.2)
|
14
|
+
language_server-protocol (3.17.0.5)
|
15
|
+
lint_roller (1.1.0)
|
16
|
+
minitest (5.25.5)
|
17
|
+
minitest-reporters (1.7.1)
|
18
|
+
ansi
|
19
|
+
builder
|
20
|
+
minitest (>= 5.0)
|
21
|
+
ruby-progressbar
|
22
|
+
parallel (1.27.0)
|
23
|
+
parser (3.3.8.0)
|
69
24
|
ast (~> 2.4.1)
|
70
25
|
racc
|
71
|
-
|
72
|
-
|
73
|
-
racc (1.8.0)
|
74
|
-
rack (3.1.4)
|
75
|
-
rack-session (2.0.0)
|
76
|
-
rack (>= 3.0.0)
|
77
|
-
rack-test (2.1.0)
|
78
|
-
rack (>= 1.3)
|
79
|
-
rackup (2.1.0)
|
80
|
-
rack (>= 3)
|
81
|
-
webrick (~> 1.8)
|
82
|
-
rails-dom-testing (2.2.0)
|
83
|
-
activesupport (>= 5.0.0)
|
84
|
-
minitest
|
85
|
-
nokogiri (>= 1.6)
|
86
|
-
rails-html-sanitizer (1.6.0)
|
87
|
-
loofah (~> 2.21)
|
88
|
-
nokogiri (~> 1.14)
|
89
|
-
railties (7.1.3.4)
|
90
|
-
actionpack (= 7.1.3.4)
|
91
|
-
activesupport (= 7.1.3.4)
|
92
|
-
irb
|
93
|
-
rackup (>= 1.0.0)
|
94
|
-
rake (>= 12.2)
|
95
|
-
thor (~> 1.0, >= 1.2.2)
|
96
|
-
zeitwerk (~> 2.6)
|
26
|
+
prism (1.4.0)
|
27
|
+
racc (1.8.1)
|
97
28
|
rainbow (3.1.1)
|
98
|
-
rake (13.
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
reline (0.5.9)
|
103
|
-
io-console (~> 0.5)
|
104
|
-
rexml (3.3.0)
|
105
|
-
strscan
|
106
|
-
rspec-core (3.13.0)
|
107
|
-
rspec-support (~> 3.13.0)
|
108
|
-
rspec-expectations (3.13.1)
|
109
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
110
|
-
rspec-support (~> 3.13.0)
|
111
|
-
rspec-mocks (3.13.1)
|
112
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
113
|
-
rspec-support (~> 3.13.0)
|
114
|
-
rspec-rails (6.1.3)
|
115
|
-
actionpack (>= 6.1)
|
116
|
-
activesupport (>= 6.1)
|
117
|
-
railties (>= 6.1)
|
118
|
-
rspec-core (~> 3.13)
|
119
|
-
rspec-expectations (~> 3.13)
|
120
|
-
rspec-mocks (~> 3.13)
|
121
|
-
rspec-support (~> 3.13)
|
122
|
-
rspec-support (3.13.1)
|
123
|
-
rubocop (1.64.1)
|
29
|
+
rake (13.3.0)
|
30
|
+
regexp_parser (2.10.0)
|
31
|
+
rexml (3.4.1)
|
32
|
+
rubocop (1.76.2)
|
124
33
|
json (~> 2.3)
|
125
|
-
language_server-protocol (
|
34
|
+
language_server-protocol (~> 3.17.0.2)
|
35
|
+
lint_roller (~> 1.1.0)
|
126
36
|
parallel (~> 1.10)
|
127
37
|
parser (>= 3.3.0.2)
|
128
38
|
rainbow (>= 2.2.2, < 4.0)
|
129
|
-
regexp_parser (>=
|
130
|
-
|
131
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
39
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
40
|
+
rubocop-ast (>= 1.45.1, < 2.0)
|
132
41
|
ruby-progressbar (~> 1.7)
|
133
|
-
unicode-display_width (>= 2.4.0, <
|
134
|
-
rubocop-ast (1.
|
135
|
-
parser (>= 3.3.
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
rubocop (
|
42
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
43
|
+
rubocop-ast (1.45.1)
|
44
|
+
parser (>= 3.3.7.2)
|
45
|
+
prism (~> 1.4)
|
46
|
+
rubocop-minitest (0.38.1)
|
47
|
+
lint_roller (~> 1.1)
|
48
|
+
rubocop (>= 1.75.0, < 2.0)
|
49
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
50
|
+
rubocop-performance (1.25.0)
|
51
|
+
lint_roller (~> 1.1)
|
52
|
+
rubocop (>= 1.75.0, < 2.0)
|
53
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
54
|
+
rubocop-rake (0.7.1)
|
55
|
+
lint_roller (~> 1.1)
|
56
|
+
rubocop (>= 1.72.1)
|
141
57
|
ruby-progressbar (1.13.0)
|
142
58
|
simplecov (0.22.0)
|
143
59
|
docile (~> 1.1)
|
@@ -146,35 +62,33 @@ GEM
|
|
146
62
|
simplecov-cobertura (2.1.0)
|
147
63
|
rexml
|
148
64
|
simplecov (~> 0.19)
|
149
|
-
simplecov-html (0.
|
65
|
+
simplecov-html (0.13.1)
|
150
66
|
simplecov_json_formatter (0.1.4)
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
concurrent-ruby (~> 1.0)
|
156
|
-
unicode-display_width (2.5.0)
|
157
|
-
webrick (1.8.1)
|
158
|
-
yard (0.9.36)
|
159
|
-
zeitwerk (2.6.16)
|
67
|
+
unicode-display_width (3.1.4)
|
68
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
69
|
+
unicode-emoji (4.0.4)
|
70
|
+
yard (0.9.37)
|
160
71
|
|
161
72
|
PLATFORMS
|
162
73
|
arm64-darwin-22
|
74
|
+
arm64-darwin-23
|
75
|
+
arm64-darwin-24
|
163
76
|
x64-mingw-ucrt
|
164
77
|
x86_64-darwin-20
|
165
78
|
x86_64-linux
|
166
79
|
|
167
80
|
DEPENDENCIES
|
168
|
-
minitest (
|
81
|
+
minitest (~> 5.24)
|
82
|
+
minitest-reporters (~> 1.7)
|
169
83
|
others!
|
170
|
-
rake (
|
171
|
-
|
172
|
-
rubocop (
|
173
|
-
rubocop-performance (
|
174
|
-
rubocop-
|
175
|
-
simplecov (
|
176
|
-
simplecov-cobertura (
|
177
|
-
yard (
|
84
|
+
rake (~> 13.2)
|
85
|
+
rubocop (~> 1.65)
|
86
|
+
rubocop-minitest (> 0)
|
87
|
+
rubocop-performance (> 0)
|
88
|
+
rubocop-rake (> 0)
|
89
|
+
simplecov (~> 0.22)
|
90
|
+
simplecov-cobertura (~> 2.1)
|
91
|
+
yard (~> 0.9)
|
178
92
|
|
179
93
|
BUNDLED WITH
|
180
|
-
2.
|
94
|
+
2.5.16
|
data/LICENSE.txt
CHANGED
data/LICENSES/MIT.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the 'Software'), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
# Functions as Objects
|
1
|
+
# Functions as Objects, in Ruby
|
2
2
|
|
3
|
-
[](https://www.rultor.com/p/yegor256/others)
|
4
4
|
[](https://www.jetbrains.com/ruby/)
|
5
5
|
|
6
6
|
[](https://github.com/yegor256/others/actions/workflows/rake.yml)
|
7
|
-
[](
|
7
|
+
[](https://www.0pdd.com/p?name=yegor256/others)
|
8
|
+
[](https://badge.fury.io/rb/others)
|
9
9
|
[](https://codecov.io/github/yegor256/others?branch=master)
|
10
|
-
[](https://rubydoc.info/github/yegor256/others/master/frames)
|
11
11
|
[](https://hitsofcode.com/view/github/yegor256/others)
|
12
12
|
[](https://github.com/yegor256/others/blob/master/LICENSE.txt)
|
13
13
|
|
@@ -33,17 +33,35 @@ class Foo
|
|
33
33
|
args[1] + 10
|
34
34
|
end
|
35
35
|
end
|
36
|
+
x = Foo.new
|
36
37
|
assert(x.foo(10) == 11)
|
37
38
|
assert(x.bar(42) == 52)
|
38
39
|
```
|
39
40
|
|
40
|
-
|
41
|
+
For example, you can create a decorator that
|
42
|
+
intercepts all method calls and logs them:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
logger = others(base: original_object) do |*args, &block|
|
46
|
+
puts "Method #{args[0]} called with #{args[1..-1].inspect}"
|
47
|
+
@base.__send__(*args, &block)
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
It also supports forwarding blocks:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
x = others(foo: 42) do |*args|
|
55
|
+
@foo + args.last.call # this is the block, as the last argument
|
56
|
+
end
|
57
|
+
puts x.bar { 12 } # => 54
|
58
|
+
```
|
41
59
|
|
42
60
|
## How to contribute
|
43
61
|
|
44
62
|
Read
|
45
63
|
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
46
|
-
Make sure
|
64
|
+
Make sure your build is green before you contribute
|
47
65
|
your pull request. You will need to have
|
48
66
|
[Ruby](https://www.ruby-lang.org/en/) 3.2+ and
|
49
67
|
[Bundler](https://bundler.io/) installed. Then:
|
data/REUSE.toml
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
|
2
|
+
# SPDX-License-Identifier: MIT
|
3
|
+
|
4
|
+
version = 1
|
5
|
+
[[annotations]]
|
6
|
+
path = [
|
7
|
+
".DS_Store",
|
8
|
+
".gitattributes",
|
9
|
+
".gitignore",
|
10
|
+
".pdd",
|
11
|
+
"**.json",
|
12
|
+
"**.md",
|
13
|
+
"**.txt",
|
14
|
+
"**/.DS_Store",
|
15
|
+
"**/.gitignore",
|
16
|
+
"**/.pdd",
|
17
|
+
"**/*.csv",
|
18
|
+
"**/*.jpg",
|
19
|
+
"**/*.json",
|
20
|
+
"**/*.md",
|
21
|
+
"**/*.pdf",
|
22
|
+
"**/*.png",
|
23
|
+
"**/*.svg",
|
24
|
+
"**/*.txt",
|
25
|
+
"**/*.vm",
|
26
|
+
"**/CNAME",
|
27
|
+
"**/Gemfile.lock",
|
28
|
+
"Gemfile.lock",
|
29
|
+
"README.md",
|
30
|
+
"renovate.json",
|
31
|
+
]
|
32
|
+
precedence = "override"
|
33
|
+
SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
|
34
|
+
SPDX-License-Identifier = "MIT"
|
data/Rakefile
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'rubygems'
|
24
7
|
require 'rake'
|
@@ -32,7 +15,7 @@ def version
|
|
32
15
|
Gem::Specification.load(Dir['*.gemspec'].first).version
|
33
16
|
end
|
34
17
|
|
35
|
-
task default: %i[clean test rubocop yard
|
18
|
+
task default: %i[clean test rubocop yard]
|
36
19
|
|
37
20
|
require 'rake/testtask'
|
38
21
|
desc 'Run all unit tests'
|
@@ -54,13 +37,4 @@ require 'rubocop/rake_task'
|
|
54
37
|
desc 'Run RuboCop on all directories'
|
55
38
|
RuboCop::RakeTask.new(:rubocop) do |task|
|
56
39
|
task.fail_on_error = true
|
57
|
-
task.requires << 'rubocop-rspec'
|
58
|
-
end
|
59
|
-
|
60
|
-
task :copyright do
|
61
|
-
sh "grep -q -r '#{Date.today.strftime('%Y')}' \
|
62
|
-
--include '*.rb' \
|
63
|
-
--include '*.txt' \
|
64
|
-
--include 'Rakefile' \
|
65
|
-
."
|
66
40
|
end
|
data/lib/others.rb
CHANGED
@@ -1,29 +1,41 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
5
|
+
|
6
|
+
# Creates an object that responds to any method call by executing a provided block.
|
4
7
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
8
|
+
# This method can be used in two ways:
|
9
|
+
# 1. As a standalone function to create an object with dynamic method handling
|
10
|
+
# 2. Inside a class definition to add catch-all method handling to instances
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
12
|
+
# @param attrs [Hash] Instance variables to set on the created object (only for standalone usage)
|
13
|
+
# @param block [Proc] The block to execute when any method is called on the object
|
14
14
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
|
23
|
-
#
|
15
|
+
# @example Standalone usage with instance variables
|
16
|
+
# obj = others(counter: 0) do |method_name, *args|
|
17
|
+
# @counter += args.first
|
18
|
+
# end
|
19
|
+
# obj.add(5) # => 5
|
20
|
+
# obj.increment(3) # => 8
|
21
|
+
#
|
22
|
+
# @example Class usage for catch-all methods
|
23
|
+
# class Calculator
|
24
|
+
# def add(a, b)
|
25
|
+
# a + b
|
26
|
+
# end
|
27
|
+
# others do |method_name, *args|
|
28
|
+
# args.reduce(:*)
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
# calc = Calculator.new
|
32
|
+
# calc.add(2, 3) # => 5 (defined method)
|
33
|
+
# calc.multiply(2, 3, 4) # => 24 (caught by others)
|
34
|
+
#
|
35
|
+
# @return [Object] An instance that responds to any method call
|
24
36
|
#
|
25
37
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
26
|
-
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
38
|
+
# Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
|
27
39
|
# License:: MIT
|
28
40
|
def others(attrs = {}, &block)
|
29
41
|
if is_a?(Class)
|
@@ -32,16 +44,30 @@ def others(attrs = {}, &block)
|
|
32
44
|
class_variable_set(:@@__others_block__, b)
|
33
45
|
# rubocop:enable Style/ClassVars
|
34
46
|
|
35
|
-
|
36
|
-
|
47
|
+
# Handles all undefined method calls by executing the stored block.
|
48
|
+
#
|
49
|
+
# @param args [Array] Method name and arguments passed to the undefined method
|
50
|
+
# @raise [RuntimeError] If a block is provided to the method call
|
51
|
+
# @return [Object] The result of executing the stored block
|
52
|
+
def method_missing(*args, &block)
|
37
53
|
b = self.class.class_variable_get(:@@__others_block__)
|
38
|
-
instance_exec(*args, &b)
|
54
|
+
instance_exec(*args + [block], &b)
|
39
55
|
end
|
40
56
|
|
57
|
+
# Always returns true to indicate this object responds to any method.
|
58
|
+
#
|
59
|
+
# @param _mtd [Symbol, String] The method name being queried
|
60
|
+
# @param _inc [Boolean] Whether to include private methods
|
61
|
+
# @return [true] Always returns true
|
41
62
|
def respond_to?(_mtd, _inc = false)
|
42
63
|
true
|
43
64
|
end
|
44
65
|
|
66
|
+
# Indicates that any missing method should be considered as responding.
|
67
|
+
#
|
68
|
+
# @param _mtd [Symbol, String] The method name being queried
|
69
|
+
# @param _inc [Boolean] Whether to include private methods
|
70
|
+
# @return [true] Always returns true
|
45
71
|
def respond_to_missing?(_mtd, _inc = false)
|
46
72
|
true
|
47
73
|
end
|
@@ -59,15 +85,29 @@ def others(attrs = {}, &block)
|
|
59
85
|
@block = block
|
60
86
|
end
|
61
87
|
|
62
|
-
|
63
|
-
|
64
|
-
|
88
|
+
# Handles all undefined method calls by executing the stored block.
|
89
|
+
#
|
90
|
+
# @param args [Array] Method name and arguments passed to the undefined method
|
91
|
+
# @raise [RuntimeError] If a block is provided to the method call
|
92
|
+
# @return [Object] The result of executing the stored block
|
93
|
+
def method_missing(*args, &block)
|
94
|
+
instance_exec(*args + [block], &@block)
|
65
95
|
end
|
66
96
|
|
97
|
+
# Always returns true to indicate this object responds to any method.
|
98
|
+
#
|
99
|
+
# @param _mtd [Symbol, String] The method name being queried
|
100
|
+
# @param _inc [Boolean] Whether to include private methods
|
101
|
+
# @return [true] Always returns true
|
67
102
|
def respond_to?(_mtd, _inc = false)
|
68
103
|
true
|
69
104
|
end
|
70
105
|
|
106
|
+
# Indicates that any missing method should be considered as responding.
|
107
|
+
#
|
108
|
+
# @param _mtd [Symbol, String] The method name being queried
|
109
|
+
# @param _inc [Boolean] Whether to include private methods
|
110
|
+
# @return [true] Always returns true
|
71
111
|
def respond_to_missing?(_mtd, _inc = false)
|
72
112
|
true
|
73
113
|
end
|
data/others.gemspec
CHANGED
@@ -1,24 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
require 'English'
|
24
7
|
require_relative 'lib/others'
|
@@ -27,7 +10,7 @@ Gem::Specification.new do |s|
|
|
27
10
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
28
11
|
s.required_ruby_version = '>=3.0'
|
29
12
|
s.name = 'others'
|
30
|
-
s.version = '0.0
|
13
|
+
s.version = '0.1.0'
|
31
14
|
s.license = 'MIT'
|
32
15
|
s.summary = 'others'
|
33
16
|
s.description =
|
data/test/test__helper.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Copyright (c) 2024 Yegor Bugayenko
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the 'Software'), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in all
|
13
|
-
# copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
# SOFTWARE.
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
|
4
|
+
# SPDX-License-Identifier: MIT
|
22
5
|
|
23
6
|
$stdout.sync = true
|
24
7
|
|
25
8
|
require 'simplecov'
|
26
|
-
SimpleCov.start
|
27
|
-
|
28
9
|
require 'simplecov-cobertura'
|
29
|
-
SimpleCov.
|
10
|
+
unless SimpleCov.running
|
11
|
+
SimpleCov.command_name('test')
|
12
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
13
|
+
[
|
14
|
+
SimpleCov::Formatter::HTMLFormatter,
|
15
|
+
SimpleCov::Formatter::CoberturaFormatter
|
16
|
+
]
|
17
|
+
)
|
18
|
+
SimpleCov.minimum_coverage 95
|
19
|
+
SimpleCov.minimum_coverage_by_file 90
|
20
|
+
SimpleCov.start do
|
21
|
+
add_filter 'test/'
|
22
|
+
add_filter 'vendor/'
|
23
|
+
add_filter 'target/'
|
24
|
+
track_files 'lib/**/*.rb'
|
25
|
+
track_files '*.rb'
|
26
|
+
end
|
27
|
+
end
|
30
28
|
|
31
29
|
require 'minitest/autorun'
|
30
|
+
require 'minitest/reporters'
|
31
|
+
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]
|