Skip to content

Commit dfc4e46

Browse files
author
ci-build
committed
[skip ci] Update site
1 parent e3cf05e commit dfc4e46

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

index.html

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,12 +762,17 @@ <h1>Ruby Style Guide</h1>
762762
<li><a href="#no-exceptional-flows">Using Exceptions for Flow of Control</a></li>
763763
<li><a href="#no-blind-rescues">Blind Rescues</a></li>
764764
<li><a href="#exception-ordering">Exception Rescuing Ordering</a></li>
765+
<li><a href="#standard-exceptions">Standard Exceptions</a></li>
766+
</ul>
767+
</li>
768+
<li><a href="#files">Files</a>
769+
<ul class="sectlevel2">
765770
<li><a href="#file-read">Reading from a file</a></li>
766771
<li><a href="#file-write">Writing to a file</a></li>
767772
<li><a href="#release-resources">Release External Resources</a></li>
768773
<li><a href="#auto-release-resources">Auto-release External Resources</a></li>
769774
<li><a href="#atomic-file-operations">Atomic File Operations</a></li>
770-
<li><a href="#standard-exceptions">Standard Exceptions</a></li>
775+
<li><a href="#null-devices">Null Devices</a></li>
771776
</ul>
772777
</li>
773778
<li><a href="#assignment-comparison">Assignment &amp; Comparison</a>
@@ -3638,6 +3643,17 @@ <h3 id="exception-ordering"><a class="anchor" href="#exception-ordering"></a><a
36383643
</div>
36393644
</div>
36403645
<div class="sect2">
3646+
<h3 id="standard-exceptions"><a class="anchor" href="#standard-exceptions"></a><a class="link" href="#standard-exceptions">Standard Exceptions</a></h3>
3647+
<div class="paragraph">
3648+
<p>Prefer the use of exceptions from the standard library over introducing new exception classes.</p>
3649+
</div>
3650+
</div>
3651+
</div>
3652+
</div>
3653+
<div class="sect1">
3654+
<h2 id="files"><a class="anchor" href="#files"></a><a class="link" href="#files">Files</a></h2>
3655+
<div class="sectionbody">
3656+
<div class="sect2">
36413657
<h3 id="file-read"><a class="anchor" href="#file-read"></a><a class="link" href="#file-read">Reading from a file</a></h3>
36423658
<div class="paragraph">
36433659
<p>Use the convenience methods <code>File.read</code> or <code>File.binread</code> when only reading a file start to finish in a single operation.</p>
@@ -3771,9 +3787,21 @@ <h3 id="atomic-file-operations"><a class="anchor" href="#atomic-file-operations"
37713787
</div>
37723788
</div>
37733789
<div class="sect2">
3774-
<h3 id="standard-exceptions"><a class="anchor" href="#standard-exceptions"></a><a class="link" href="#standard-exceptions">Standard Exceptions</a></h3>
3790+
<h3 id="null-devices"><a class="anchor" href="#null-devices"></a><a class="link" href="#null-devices">Null Devices</a></h3>
37753791
<div class="paragraph">
3776-
<p>Prefer the use of exceptions from the standard library over introducing new exception classes.</p>
3792+
<p>Use the platform independent null device (<code>File::NULL</code>) rather than hardcoding a value (<code>/dev/null</code> on Unix-like OSes, <code>NUL</code> or <code>NUL:</code> on Windows).</p>
3793+
</div>
3794+
<div class="listingblock">
3795+
<div class="content">
3796+
<pre class="rouge highlight"><code data-lang="ruby"><span class="c1"># bad - hardcoded devices are platform specific</span>
3797+
<span class="no">File</span><span class="p">.</span><span class="nf">open</span><span class="p">(</span><span class="s2">"/dev/null"</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span>
3798+
3799+
<span class="c1"># bad - unnecessary ternary can be replaced with `File::NULL`</span>
3800+
<span class="no">File</span><span class="p">.</span><span class="nf">open</span><span class="p">(</span><span class="no">Gem</span><span class="p">.</span><span class="nf">win_platform?</span> <span class="p">?</span> <span class="s1">'NUL'</span> <span class="p">:</span> <span class="s1">'/dev/null'</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span>
3801+
3802+
<span class="c1"># good - platform independent</span>
3803+
<span class="no">File</span><span class="p">.</span><span class="nf">open</span><span class="p">(</span><span class="no">File</span><span class="o">::</span><span class="no">NULL</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span></code></pre>
3804+
</div>
37773805
</div>
37783806
</div>
37793807
</div>
@@ -8445,7 +8473,7 @@ <h2 id="spread-the-word"><a class="anchor" href="#spread-the-word"></a><a class=
84458473
</div>
84468474
<div id="footer">
84478475
<div id="footer-text">
8448-
Last updated 2024-12-18 06:54:25 UTC
8476+
Last updated 2025-03-31 18:25:47 UTC
84498477
</div>
84508478
</div>
84518479
</body>

0 commit comments

Comments
 (0)