class RuboCop::Cop::Lint::MultipleCompare
10 <= x && x <= 20
x < y && y < z
# good
@example
10 <= x <= 20
x < y < z
# bad
@example
comparison operators.
the comparison is not syntax error. This cop checks the bad usage of
multiple value. However, we can’t use the comparison in Ruby. However,
In math and Python, we can use ‘x < y < z` style comparison to compare
def autocorrect(node)
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
def on_send(node)
def on_send(node) return unless multiple_compare?(node) add_offense(node) end