Skip to content

Files

Latest commit

 

History

History
31 lines (21 loc) · 538 Bytes

Style-EachForSimpleLoop.md

File metadata and controls

31 lines (21 loc) · 538 Bytes

Pattern: Use of each for simple loop

Issue: -

Description

This rule checks for loops which iterate a constant number of times, using a Range literal and #each. This can be done more readably using Integer#times.

This check only applies if the block takes no parameters.

Examples

# bad
(1..5).each { }

# good
5.times { }
# bad
(0...10).each {}

# good
10.times {}

Further Reading