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

Style/ExplicitBlockArgument-20240104233316 #12

Merged
merged 4 commits into from
Jan 17, 2024

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jan 4, 2024

Rubocop challenge!

Style/ExplicitBlockArgument

Safe autocorrect: Yes
✅ The autocorrect a cop does is safe (equivalent) by design.

Description

Overview

Enforces the use of explicit block argument to avoid writing
block literal that just passes its arguments to another block.

NOTE: This cop only registers an offense if the block args match the
yield args exactly.

Examples

# bad
def with_tmp_dir
  Dir.mktmpdir do |tmp_dir|
    Dir.chdir(tmp_dir) { |dir| yield dir } # block just passes arguments
  end
end

# bad
def nine_times
  9.times { yield }
end

# good
def with_tmp_dir(&block)
  Dir.mktmpdir do |tmp_dir|
    Dir.chdir(tmp_dir, &block)
  end
end

with_tmp_dir do |dir|
  puts "dir is accessible as a parameter and pwd is set: #{dir}"
end

# good
def nine_times(&block)
  9.times(&block)
end

Auto generated by rubocop_challenger

@@ -10,7 +10,7 @@ def initialize
end

def each(&block)
cell_references.each { |cell_reference| yield(cell_reference) }
cell_references.each(&block)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phenchaw opinion ?

@mathieujobin mathieujobin merged commit 99678fa into master Jan 17, 2024
30 checks passed
@mathieujobin mathieujobin deleted the rubocop-challenge/20240104233316 branch January 17, 2024 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

1 participant