diff --git a/README.adoc b/README.adoc index 132e6c29..2e1ab1b7 100644 --- a/README.adoc +++ b/README.adoc @@ -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. @@ -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