Skip to content

Commit

Permalink
Merge pull request rubocop#38 from burke/unlesselse
Browse files Browse the repository at this point in the history
Added unless/else guideline
  • Loading branch information
bbatsov committed Sep 20, 2011
2 parents d13cd9d + 7733e3e commit 3e91948
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -189,6 +189,7 @@ community.
```

* Avoid multi-line ?: (the ternary operator), use `if/unless` instead.

* Favor modifier `if/unless` usage when you have a single-line
body. Another good alternative is the usage of control flow `and/or`.

Expand Down Expand Up @@ -218,6 +219,23 @@ community.
# another good option
some_condition or do_something
```
* Never use `unless` with `else`. Rewrite these with the positive case first.

```Ruby
#bad
unless success?
puts "failure"
else
puts "success"
end

#good
if success?
puts "success"
else
puts "failure"
end
```

* Suppress superfluous parentheses when calling methods, but keep them
when calling "functions", i.e. when you use the return value in the
Expand Down

0 comments on commit 3e91948

Please sign in to comment.