class RubbyCop::Cop::Lint::MultipleCompare

In math and Python, we can use `x < y < z` style comparison to compare multiple value. However, we can't use the comparison in Ruby. However, the comparison is not syntax error. This cop checks the bad usage of comparison operators.

@example

# bad

x < y < z
10 <= x <= 20

@example

# good

x < y && y < z
10 <= x && x <= 20

Constants

MSG

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubbycop/cop/lint/multiple_compare.rb, line 37
def autocorrect(node)
  center = multiple_compare?(node)
  new_center = "#{center.source} && #{center.source}"

  lambda do |corrector|
    corrector.replace(center.source_range, new_center)
  end
end
on_send(node) click to toggle source
# File lib/rubbycop/cop/lint/multiple_compare.rb, line 31
def on_send(node)
  return unless multiple_compare?(node)

  add_offense(node, :expression)
end