Skip to content

Commit 7b2b7b4

Browse files
committed
Add section on platform independent null devices
1 parent ff3ce80 commit 7b2b7b4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

README.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,22 @@ end
22942294
FileUtils.rm_f(path)
22952295
----
22962296

2297+
=== Null Devices [[null-devices]]
2298+
2299+
Use the platform independent null device (`File::NULL`) rather than hardcoding a value (`/dev/null` on Unix-like OSes, `NUL` or `NUL:` on Windows).
2300+
2301+
[source,ruby]
2302+
----
2303+
# bad - hardcoded devices are platform specfic
2304+
File.open("/dev/null", 'w') { ... }
2305+
2306+
# bad - unnecessary ternary can be replaced with `File::NULL`
2307+
File.open(Gem.win_platform? ? 'NUL' : '/dev/null', 'w') { ... }
2308+
2309+
# good - platform independent
2310+
File.open(File::NULL, 'w') { ... }
2311+
----
2312+
22972313
== Assignment & Comparison
22982314

22992315
=== Parallel Assignment [[parallel-assignment]]

0 commit comments

Comments
 (0)