From ff3ce808cd506ffe422059522ee7c885868ffd09 Mon Sep 17 00:00:00 2001 From: Daniel Vandersluis Date: Tue, 26 Nov 2024 10:00:03 -0500 Subject: [PATCH 1/2] Reorganize practices around files out of the "Exceptions" section --- README.adoc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.adoc b/README.adoc index 132e6c29..980bdcb5 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,10 +2294,6 @@ end FileUtils.rm_f(path) ---- -=== Standard Exceptions [[standard-exceptions]] - -Prefer the use of exceptions from the standard library over introducing new exception classes. - == Assignment & Comparison === Parallel Assignment [[parallel-assignment]] From 4f11e71a1f2d02b187ff48f9f04a28b76a83d69f Mon Sep 17 00:00:00 2001 From: Daniel Vandersluis Date: Tue, 26 Nov 2024 10:06:36 -0500 Subject: [PATCH 2/2] Add section on platform independent null devices --- README.adoc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.adoc b/README.adoc index 980bdcb5..2e1ab1b7 100644 --- a/README.adoc +++ b/README.adoc @@ -2294,6 +2294,22 @@ end FileUtils.rm_f(path) ---- +=== Null Devices [[null-devices]] + +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 === Parallel Assignment [[parallel-assignment]]