Skip to content

Files

Latest commit

 

History

History
32 lines (22 loc) · 587 Bytes

Style-ComparableClamp.md

File metadata and controls

32 lines (22 loc) · 587 Bytes

Pattern: Missing use of Comparable#clamp

Issue: -

Description

Enforces the use of Comparable#clamp instead of comparison by minimum and maximum.

This rule supports autocorrection for if/elsif/else bad style only. Because ArgumentError occurs if the minimum and maximum of clamp arguments are reversed.

Examples

# bad
[[x, low].max, high].min

# bad
if x < low
  low
elsif high < x
  high
else
  x
end

# good
x.clamp(low, high)

Further Reading