Project

General

Profile

Actions

Patch #32308

closed

Rubocop: Performance/RedundantBlockCall: Use yield instead of block.call.

Added by Marius BĂLTEANU over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Toshi MARUYAMA
Category:
Code cleanup/refactoring
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

Description


Offenses:

lib/redmine/scm/adapters/abstract_adapter.rb:252:17: C: [Corrected] Performance/RedundantBlockCall: Use yield instead of block.call.
                block.call(io) if block_given?
                ^^^^^^^^^^^^^^

Fix:

root@df2fd1389bf4:/work# git diff
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb
index 67a1f17a3..14f8f09c4 100644
--- a/lib/redmine/scm/adapters/abstract_adapter.rb
+++ b/lib/redmine/scm/adapters/abstract_adapter.rb
@@ -249,7 +249,7 @@ module Redmine
               IO.popen(cmd, mode) do |io|
                 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
                 io.close_write unless options[:write_stdin]
-                block.call(io) if block_given?
+                yield(io) if block_given?
               end
             rescue => e
               msg = strip_credential(e.message)


Files

yield.patch (3.63 KB) yield.patch Pavel Rosický, 2019-10-21 13:32
block_given.patch (365 Bytes) block_given.patch Pavel Rosický, 2019-10-21 13:35
Actions #1

Updated by Go MAEDA over 4 years ago

Caused by r18777.

Actions #3

Updated by Pavel Rosický over 4 years ago

there are a few other cases

Actions #5

Updated by Marius BĂLTEANU over 4 years ago

  • Assignee set to Toshi MARUYAMA
Actions #6

Updated by Toshi MARUYAMA over 4 years ago

def check(&block)
  if block
    puts "if block" 
  else
    puts "else" 
  end

  if block_given?
    puts "Block is given." 
  else
    puts "Block isn't given." 
  end
end

check{}
puts
check
$ ruby test.rb 
if block
Block is given.

else
Block isn't given.

Actions #7

Updated by Toshi MARUYAMA over 4 years ago

  • Status changed from New to Closed
  • Target version deleted (Candidate for next major release)

Fixed, thanks.

Actions

Also available in: Atom PDF