others 0.0.3 → 0.1.1

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.
data/Gemfile.lock CHANGED
@@ -6,138 +6,54 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (7.1.3.4)
10
- actionview (= 7.1.3.4)
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
- concurrent-ruby (1.3.3)
40
- connection_pool (2.4.1)
41
- crass (1.0.6)
42
- diff-lcs (1.5.1)
43
- docile (1.4.0)
44
- drb (2.2.1)
45
- erubi (1.13.0)
46
- i18n (1.14.5)
47
- concurrent-ruby (~> 1.0)
48
- io-console (0.7.2)
49
- irb (1.13.2)
50
- rdoc (>= 4.0.0)
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
- psych (5.1.2)
72
- stringio
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.2.1)
99
- rdoc (6.7.0)
100
- psych (>= 4.0.0)
101
- regexp_parser (2.9.2)
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 (>= 3.17.0)
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 (>= 1.8, < 3.0)
130
- rexml (>= 3.2.5, < 4.0)
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, < 3.0)
134
- rubocop-ast (1.31.3)
135
- parser (>= 3.3.1.0)
136
- rubocop-performance (1.21.1)
137
- rubocop (>= 1.48.1, < 2.0)
138
- rubocop-ast (>= 1.31.1, < 2.0)
139
- rubocop-rspec (3.0.1)
140
- rubocop (~> 1.61)
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.12.3)
65
+ simplecov-html (0.13.1)
150
66
  simplecov_json_formatter (0.1.4)
151
- stringio (3.1.1)
152
- strscan (3.1.0)
153
- thor (1.3.1)
154
- tzinfo (2.0.6)
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 (= 5.24.0)
81
+ minitest (~> 5.24)
82
+ minitest-reporters (~> 1.7)
169
83
  others!
170
- rake (= 13.2.1)
171
- rspec-rails (= 6.1.3)
172
- rubocop (= 1.64.1)
173
- rubocop-performance (= 1.21.1)
174
- rubocop-rspec (= 3.0.1)
175
- simplecov (= 0.22.0)
176
- simplecov-cobertura (= 2.1.0)
177
- yard (= 0.9.36)
84
+ rake (~> 13.2)
85
+ rubocop (~> 1.65)
86
+ rubocop-minitest (~> 0.38)
87
+ rubocop-performance (~> 1.0)
88
+ rubocop-rake (~> 0.7)
89
+ simplecov (~> 0.22)
90
+ simplecov-cobertura (~> 2.1)
91
+ yard (~> 0.9)
178
92
 
179
93
  BUNDLED WITH
180
- 2.4.22
94
+ 2.5.16
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024 Yegor Bugayenko
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
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/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
- [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/others)](http://www.rultor.com/p/yegor256/others)
3
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/others)](https://www.rultor.com/p/yegor256/others)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
5
 
6
6
  [![rake](https://github.com/yegor256/others/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/others/actions/workflows/rake.yml)
7
- [![PDD status](http://www.0pdd.com/svg?name=yegor256/others)](http://www.0pdd.com/p?name=yegor256/others)
8
- [![Gem Version](https://badge.fury.io/rb/others.svg)](http://badge.fury.io/rb/others)
7
+ [![PDD status](https://www.0pdd.com/svg?name=yegor256/others)](https://www.0pdd.com/p?name=yegor256/others)
8
+ [![Gem Version](https://badge.fury.io/rb/others.svg)](https://badge.fury.io/rb/others)
9
9
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/others.svg)](https://codecov.io/github/yegor256/others?branch=master)
10
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/others/master/frames)
10
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/others/master/frames)
11
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/others)](https://hitsofcode.com/view/github/yegor256/others)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](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
- That's it.
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 you build is green before you contribute
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 copyright]
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,77 +1,122 @@
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
- # A function that catches all undeclared methods.
24
- #
25
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
27
- # License:: MIT
28
- def others(attrs = {}, &block)
29
- if is_a?(Class)
30
- class_exec(block) do |b|
31
- # rubocop:disable Style/ClassVars
32
- class_variable_set(:@@__others_block__, b)
33
- # rubocop:enable Style/ClassVars
6
+ # System module.
7
+ module Kernel
8
+ # Creates an object that responds to any method call by executing a provided block.
9
+ #
10
+ # This method can be used in two ways:
11
+ # 1. As a standalone function to create an object with dynamic method handling
12
+ # 2. Inside a class definition to add catch-all method handling to instances
13
+ #
14
+ # @param attrs [Hash] Instance variables to set on the created object (only for standalone usage)
15
+ # @param block [Proc] The block to execute when any method is called on the object
16
+ #
17
+ # @example Standalone usage with instance variables
18
+ # obj = others(counter: 0) do |method_name, *args|
19
+ # @counter += args.first
20
+ # end
21
+ # obj.add(5) # => 5
22
+ # obj.increment(3) # => 8
23
+ #
24
+ # @example Class usage for catch-all methods
25
+ # class Calculator
26
+ # def add(a, b)
27
+ # a + b
28
+ # end
29
+ # others do |method_name, *args|
30
+ # args.reduce(:*)
31
+ # end
32
+ # end
33
+ # calc = Calculator.new
34
+ # calc.add(2, 3) # => 5 (defined method)
35
+ # calc.multiply(2, 3, 4) # => 24 (caught by others)
36
+ #
37
+ # @return [Object] An instance that responds to any method call
38
+ #
39
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
40
+ # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
41
+ # License:: MIT
42
+ def others(attrs = {}, &block)
43
+ if is_a?(Class)
44
+ class_exec(block) do |b|
45
+ # rubocop:disable Style/ClassVars
46
+ class_variable_set(:@@__others_block__, b)
47
+ # rubocop:enable Style/ClassVars
34
48
 
35
- def method_missing(*args)
36
- raise 'Block cannot be provided' if block_given?
37
- b = self.class.class_variable_get(:@@__others_block__)
38
- instance_exec(*args, &b)
39
- end
49
+ # Handles all undefined method calls by executing the stored block.
50
+ #
51
+ # @param args [Array] Method name and arguments passed to the undefined method
52
+ # @raise [RuntimeError] If a block is provided to the method call
53
+ # @return [Object] The result of executing the stored block
54
+ def method_missing(*args, &block)
55
+ b = self.class.class_variable_get(:@@__others_block__)
56
+ args += [block] if block_given?
57
+ instance_exec(*args, &b)
58
+ end
40
59
 
41
- def respond_to?(_mtd, _inc = false)
42
- true
43
- end
60
+ # Always returns true to indicate this object responds to any method.
61
+ #
62
+ # @param _mtd [Symbol, String] The method name being queried
63
+ # @param _inc [Boolean] Whether to include private methods
64
+ # @return [true] Always returns true
65
+ def respond_to?(_mtd, _inc = false)
66
+ true
67
+ end
44
68
 
45
- def respond_to_missing?(_mtd, _inc = false)
46
- true
47
- end
48
- end
49
- else
50
- c = Class.new do
51
- def initialize(attrs, &block)
52
- # rubocop:disable Style/HashEachMethods
53
- # rubocop:disable Lint/UnusedBlockArgument
54
- attrs.each do |k, v|
55
- instance_eval("@#{k} = v", __FILE__, __LINE__) # @foo = v
69
+ # Indicates that any missing method should be considered as responding.
70
+ #
71
+ # @param _mtd [Symbol, String] The method name being queried
72
+ # @param _inc [Boolean] Whether to include private methods
73
+ # @return [true] Always returns true
74
+ def respond_to_missing?(_mtd, _inc = false)
75
+ true
56
76
  end
57
- # rubocop:enable Style/HashEachMethods
58
- # rubocop:enable Lint/UnusedBlockArgument
59
- @block = block
60
77
  end
78
+ else
79
+ c = Class.new do
80
+ def initialize(attrs, &block)
81
+ # rubocop:disable Style/HashEachMethods
82
+ # rubocop:disable Lint/UnusedBlockArgument
83
+ attrs.each do |k, v|
84
+ instance_eval("@#{k} = v", __FILE__, __LINE__) # @foo = v
85
+ end
86
+ # rubocop:enable Style/HashEachMethods
87
+ # rubocop:enable Lint/UnusedBlockArgument
88
+ @block = block
89
+ end
61
90
 
62
- def method_missing(*args)
63
- raise 'Block cannot be provided' if block_given?
64
- instance_exec(*args, &@block)
65
- end
91
+ # Handles all undefined method calls by executing the stored block.
92
+ #
93
+ # @param args [Array] Method name and arguments passed to the undefined method
94
+ # @raise [RuntimeError] If a block is provided to the method call
95
+ # @return [Object] The result of executing the stored block
96
+ def method_missing(*args, &block)
97
+ args += [block] if block_given?
98
+ instance_exec(*args, &@block)
99
+ end
66
100
 
67
- def respond_to?(_mtd, _inc = false)
68
- true
69
- end
101
+ # Always returns true to indicate this object responds to any method.
102
+ #
103
+ # @param _mtd [Symbol, String] The method name being queried
104
+ # @param _inc [Boolean] Whether to include private methods
105
+ # @return [true] Always returns true
106
+ def respond_to?(_mtd, _inc = false)
107
+ true
108
+ end
70
109
 
71
- def respond_to_missing?(_mtd, _inc = false)
72
- true
110
+ # Indicates that any missing method should be considered as responding.
111
+ #
112
+ # @param _mtd [Symbol, String] The method name being queried
113
+ # @param _inc [Boolean] Whether to include private methods
114
+ # @return [true] Always returns true
115
+ def respond_to_missing?(_mtd, _inc = false)
116
+ true
117
+ end
73
118
  end
119
+ c.new(attrs, &block)
74
120
  end
75
- c.new(attrs, &block)
76
121
  end
77
122
  end
data/others.gemspec CHANGED
@@ -1,33 +1,15 @@
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
- require_relative 'lib/others'
25
7
 
26
8
  Gem::Specification.new do |s|
27
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
28
10
  s.required_ruby_version = '>=3.0'
29
11
  s.name = 'others'
30
- s.version = '0.0.3'
12
+ s.version = '0.1.1'
31
13
  s.license = 'MIT'
32
14
  s.summary = 'others'
33
15
  s.description =