Sophie

Sophie

distrib > CentOS > 5 > x86_64 > by-pkgid > 6d36cb72372cfb7c8fee63f4d6dc0530 > files > 153

ruby-docs-1.8.5-31.el5_9.x86_64.rpm

<html>
<head>
<title>Ruby FAQ: 
Undocumented Features
</title>
</head>
<body>
<a href="rubyfaq-8.html">Previous</a>
Next
<a href="rubyfaq.html#toc9">Table of contents</a>
<hr>
<h2><a name="s9">9. 
Undocumented Features
</a></h2>

<h2><a name="ss9.1">9.1 
What does <code>a ? b : c</code> mean?
</a></h2>


It means <code>if a then b else c end</code>.

<h2><a name="ss9.2">9.2 
How can I count the number of lines in a file?
</a></h2>


Assuming that the file ends in a linefeed, following code may give the
fastest result.

    <code>open(&quot;file&quot;).read.count(&quot;\n&quot;)</code>
<h2><a name="ss9.3">9.3 
What do <code>begin</code> and <code>end</code> of MatchingData return? 
</a></h2>


They act with $~, and return the start index and the end index of
matched data $0, $1... in the original string.  See an example
in <a href="rubyfaq-7.html#tab">tab expansion</a>.


<hr>
<a href="rubyfaq-8.html">Previous</a>
Next
<a href="rubyfaq.html#toc9">Table of contents</a>
</body>
<html>