Skip to content

Commit

Permalink
Add a rule about auto resource releasing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Mar 8, 2015
1 parent 2d7e03d commit b77446c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -2759,6 +2759,23 @@ condition](#safe-assignment-in-condition).
end
```
* <a name="auto-release-resources"></a>
Use versions of resource obtaining methods that do automatic
resource cleanup when possible.
<sup>[[link](#auto-release-resources)]</sup>
```Ruby
# bad - you need to close the file descriptor explicitly
f = File.open('testfile')
# ...
f.close
# good - the file descriptor is closed automatically
File.open('testfile') do |f|
# ...
end
```
* <a name="standard-exceptions"></a>
Favor the use of exceptions for the standard library over introducing new
exception classes.
Expand Down

0 comments on commit b77446c

Please sign in to comment.