Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don’t recommend omitting the block argument to define_method #3499

Closed
bquorning opened this issue Sep 15, 2016 · 0 comments
Closed

Don’t recommend omitting the block argument to define_method #3499

bquorning opened this issue Sep 15, 2016 · 0 comments
Labels

Comments

@bquorning
Copy link
Contributor

When using define_method to define a method, the block arguments given will turn into method arguments on the defined method. So when the Lint/UnusedBlockArgument cop recommends that I “can omit the argument”, it is actually suggesting that I change the arity of a method without changing its callers.

Running RuboCop with the -a flag does the right thing and prefixes the unused argument with an underscore.


Expected behavior

Recommend that I use _ prefix for unused block argument to define_method.

Actual behavior

Recommend that I use delete the “unused” block argument to define_method.

Steps to reproduce the problem

Given a file test.rb:

# encoding: utf-8
# frozen_string_literal: true

define_method('foo') do |bar|
  puts 'Completely ignores the argument'
end

foo(42)

Running RuboCop gives this output:

Inspecting 1 file
W

Offenses:

test.rb:4:26: W: Unused block argument - bar. You can omit the argument if you don't care about it.
define_method('foo') do |bar|
                         ^^^

1 file inspected, 1 offense detected

RuboCop version

$ rubocop -V
0.42.0 (using Parser 2.3.1.2, running on ruby 2.3.1 x86_64-darwin15)
@bbatsov bbatsov added the bug label Sep 16, 2016
Drenmi added a commit to Drenmi/rubocop that referenced this issue Sep 30, 2016
…method`

This cop would make recommendations that, if followed, would change
the arity of methods defined using `#define_method`. This change
fixes that.
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
…method`

This cop would make recommendations that, if followed, would change
the arity of methods defined using `#define_method`. This change
fixes that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants