class RuboCop::Cop::Performance::MethodObjectAsBlock

This cop identifies places where methods are converted to blocks, with the use of `&method`, and passed as arguments to method calls. It is faster to replace those with explicit blocks, calling those methods inside.

@example

# bad
array.map(&method(:do_something))
[1, 2, 3].each(&out.method(:puts))

# good
array.map { |x| do_something(x) }
[1, 2, 3].each { |x| out.puts(x) }

Constants

MSG

Public Instance Methods

on_block_pass(node) click to toggle source
# File lib/rubocop/cop/performance/method_object_as_block.rb, line 26
def on_block_pass(node)
  add_offense(node) if method_object_as_argument?(node)
end