class Rubocop::Cop::Style::AndOr
This cop checks for uses of and and or.
Constants
- MSG
- OPS
Public Instance Methods
on_and(node)
click to toggle source
Calls superclass method
# File lib/rubocop/cop/style/and_or.rb, line 12 def on_and(node) process_logical_op(node) super end
on_or(node)
click to toggle source
Calls superclass method
# File lib/rubocop/cop/style/and_or.rb, line 18 def on_or(node) process_logical_op(node) super end
Private Instance Methods
autocorrect_action(node)
click to toggle source
# File lib/rubocop/cop/style/and_or.rb, line 38 def autocorrect_action(node) replacement = (node.type == :and ? '&&' : '||') replace(node.loc.operator, replacement) end
process_logical_op(node)
click to toggle source
# File lib/rubocop/cop/style/and_or.rb, line 26 def process_logical_op(node) op = node.loc.operator.source op_type = node.type.to_s if op == op_type add_offence(:convention, node.loc.operator, sprintf(MSG, OPS[op], op)) do_autocorrect(node) end end