Class: RuboCop::Cop::Lecture::PreferSymbolToProc

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/lecture/prefer_symbol_to_proc.rb

Overview

TODO: 書き換え このブロックはmethod(&:method)で置き換えられるかもしれません。

Examples:

# bad
["a","b","c"].map do |x|
  x.upcase
end

# good
["a","b","c"].map(&:upcase)

Constant Summary collapse

MSG =

TODO: 追記

"\u3053\u306E\u30D6\u30ED\u30C3\u30AF\u306Fmethod(&:method)\u3067\u7F6E\u304D\u63DB\u3048\u3089\u308C\u308B\u304B\u3082\u3057\u308C\u307E\u305B\u3093\u3002\n"

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object

TODO: auto correct



25
26
27
28
29
30
31
# File 'lib/rubocop/cop/lecture/prefer_symbol_to_proc.rb', line 25

def on_block(node)
  target_nodes = node.child_nodes - [node.send_node] # ブロックが渡されている主メソッドは除く
  send_type_nodes = target_nodes.select(&:send_type?) # :begin nodeが入らず、直下にあること
  if send_type_nodes.count == 1 && !send_type_nodes.last.arguments?
    add_offense(node)
  end
end