Skip to content

Commit

Permalink
Merge pull request rubocop#317 from geniou/next
Browse files Browse the repository at this point in the history
Perfer next over conditional blocks
  • Loading branch information
bbatsov committed May 14, 2014
2 parents 6886e90 + b484901 commit 88fc53e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,10 @@ Translations of the guide are available in the following languages:
* Avoid the use of flip-flops.
* Avoid use of nested conditionals for flow of control.
Prefer a guard clause when you can assert invalid data. A guard clause is a conditional
statement at the top of a function that bails out as soon as it can.
Prefer a guard clause when you can assert invalid data. A guard clause
is a conditional statement at the top of a function that bails out as
soon as it can.
```Ruby
# bad
Expand All @@ -1484,6 +1486,23 @@ Translations of the guide are available in the following languages:
end
```
Prefer `next` in loops instead of conditional blocks.
```Ruby
# bad
[0, 1, 2, 3].each do |item|
if item > 1
puts item
end
end
# good
[0, 1, 2, 3].each do |item|
next unless item > 1
puts item
end
```
## Naming
> The only real difficulties in programming are cache invalidation and
Expand Down

0 comments on commit 88fc53e

Please sign in to comment.