Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,12 @@ rescue StandardError => e
end
----

=== Standard Exceptions [[standard-exceptions]]

Prefer the use of exceptions from the standard library over introducing new exception classes.

== Files

=== Reading from a file [[file-read]]

Use the convenience methods `File.read` or `File.binread` when only reading a file start to finish in a single operation.
Expand Down Expand Up @@ -2288,9 +2294,21 @@ end
FileUtils.rm_f(path)
----

=== Standard Exceptions [[standard-exceptions]]
=== Null Devices [[null-devices]]

Prefer the use of exceptions from the standard library over introducing new exception classes.
Use the platform independent null device (`File::NULL`) rather than hardcoding a value (`/dev/null` on Unix-like OSes, `NUL` or `NUL:` on Windows).

[source,ruby]
----
# bad - hardcoded devices are platform specific
File.open("/dev/null", 'w') { ... }

# bad - unnecessary ternary can be replaced with `File::NULL`
File.open(Gem.win_platform? ? 'NUL' : '/dev/null', 'w') { ... }

# good - platform independent
File.open(File::NULL, 'w') { ... }
----

== Assignment & Comparison

Expand Down