Skip to content

Commit

Permalink
Add section on platform independent null devices
Browse files Browse the repository at this point in the history
  • Loading branch information
dvandersluis committed Nov 26, 2024
1 parent ff3ce80 commit 4f11e71
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down

0 comments on commit 4f11e71

Please sign in to comment.