HEX
Server: Apache
System: Windows NT MAGNETO-ARM 10.0 build 22000 (Windows 10) AMD64
User: Michel (0)
PHP: 7.4.7
Disabled: NONE
Upload Files
File: C:/Ruby27-x64/share/doc/ruby/html/ARGF.html
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>class ARGF - RDoc Documentation</title>

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
</script>

<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">




<body id="top" role="document" class="class">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="./index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    <div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  
  <p class="link"><a href="Object.html">Object</a>
  
</div>

    <div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
  
  
    <li><a class="include" href="Enumerable.html">Enumerable</a>
  
  
  </ul>
</div>

    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-i-argv">#argv</a>
    
    <li ><a href="#method-i-binmode">#binmode</a>
    
    <li ><a href="#method-i-binmode-3F">#binmode?</a>
    
    <li ><a href="#method-i-bytes">#bytes</a>
    
    <li ><a href="#method-i-chars">#chars</a>
    
    <li ><a href="#method-i-close">#close</a>
    
    <li ><a href="#method-i-closed-3F">#closed?</a>
    
    <li ><a href="#method-i-codepoints">#codepoints</a>
    
    <li ><a href="#method-i-each">#each</a>
    
    <li ><a href="#method-i-each_byte">#each_byte</a>
    
    <li ><a href="#method-i-each_char">#each_char</a>
    
    <li ><a href="#method-i-each_codepoint">#each_codepoint</a>
    
    <li ><a href="#method-i-each_line">#each_line</a>
    
    <li ><a href="#method-i-eof">#eof</a>
    
    <li ><a href="#method-i-eof-3F">#eof?</a>
    
    <li ><a href="#method-i-external_encoding">#external_encoding</a>
    
    <li ><a href="#method-i-file">#file</a>
    
    <li ><a href="#method-i-filename">#filename</a>
    
    <li ><a href="#method-i-fileno">#fileno</a>
    
    <li ><a href="#method-i-getbyte">#getbyte</a>
    
    <li ><a href="#method-i-getc">#getc</a>
    
    <li ><a href="#method-i-gets">#gets</a>
    
    <li ><a href="#method-i-inplace_mode">#inplace_mode</a>
    
    <li ><a href="#method-i-inplace_mode-3D">#inplace_mode=</a>
    
    <li ><a href="#method-i-inspect">#inspect</a>
    
    <li ><a href="#method-i-internal_encoding">#internal_encoding</a>
    
    <li ><a href="#method-i-lineno">#lineno</a>
    
    <li ><a href="#method-i-lineno-3D">#lineno=</a>
    
    <li ><a href="#method-i-lines">#lines</a>
    
    <li ><a href="#method-i-path">#path</a>
    
    <li ><a href="#method-i-pos">#pos</a>
    
    <li ><a href="#method-i-pos-3D">#pos=</a>
    
    <li ><a href="#method-i-print">#print</a>
    
    <li ><a href="#method-i-printf">#printf</a>
    
    <li ><a href="#method-i-putc">#putc</a>
    
    <li ><a href="#method-i-puts">#puts</a>
    
    <li ><a href="#method-i-read">#read</a>
    
    <li ><a href="#method-i-read_nonblock">#read_nonblock</a>
    
    <li ><a href="#method-i-readbyte">#readbyte</a>
    
    <li ><a href="#method-i-readchar">#readchar</a>
    
    <li ><a href="#method-i-readline">#readline</a>
    
    <li ><a href="#method-i-readlines">#readlines</a>
    
    <li ><a href="#method-i-readpartial">#readpartial</a>
    
    <li ><a href="#method-i-rewind">#rewind</a>
    
    <li ><a href="#method-i-seek">#seek</a>
    
    <li ><a href="#method-i-set_encoding">#set_encoding</a>
    
    <li ><a href="#method-i-skip">#skip</a>
    
    <li ><a href="#method-i-tell">#tell</a>
    
    <li ><a href="#method-i-to_a">#to_a</a>
    
    <li ><a href="#method-i-to_i">#to_i</a>
    
    <li ><a href="#method-i-to_io">#to_io</a>
    
    <li ><a href="#method-i-to_s">#to_s</a>
    
    <li ><a href="#method-i-to_write_io">#to_write_io</a>
    
    <li ><a href="#method-i-write">#write</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="class-ARGF">
  <h1 id="class-ARGF" class="class">
    class ARGF
  </h1>

  <section class="description">
    
<p><code>ARGF</code> is a stream designed for use in scripts that process files given as command-line arguments or passed in via STDIN.</p>

<p>The arguments passed to your script are stored in the <code>ARGV</code> <a href="Array.html"><code>Array</code></a>, one argument per element. <code>ARGF</code> assumes that any arguments that aren&#39;t filenames have been removed from <code>ARGV</code>. For example:</p>

<pre>$ ruby argf.rb --verbose file1 file2

ARGV  #=&gt; [&quot;--verbose&quot;, &quot;file1&quot;, &quot;file2&quot;]
option = ARGV.shift #=&gt; &quot;--verbose&quot;
ARGV  #=&gt; [&quot;file1&quot;, &quot;file2&quot;]</pre>

<p>You can now use <code>ARGF</code> to work with a concatenation of each of these named files. For instance, <code>ARGF.read</code> will return the contents of <em>file1</em> followed by the contents of <em>file2</em>.</p>

<p>After a file in <code>ARGV</code> has been read <code>ARGF</code> removes it from the <a href="Array.html"><code>Array</code></a>. Thus, after all files have been read <code>ARGV</code> will be empty.</p>

<p>You can manipulate <code>ARGV</code> yourself to control what <code>ARGF</code> operates on. If you remove a file from <code>ARGV</code>, it is ignored by <code>ARGF</code>; if you add files to <code>ARGV</code>, they are treated as if they were named on the command line. For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">replace</span> [<span class="ruby-string">&quot;file1&quot;</span>]
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">readlines</span> <span class="ruby-comment"># Returns the contents of file1 as an Array</span>
<span class="ruby-constant">ARGV</span>           <span class="ruby-comment">#=&gt; []</span>
<span class="ruby-constant">ARGV</span>.<span class="ruby-identifier">replace</span> [<span class="ruby-string">&quot;file2&quot;</span>, <span class="ruby-string">&quot;file3&quot;</span>]
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">read</span>      <span class="ruby-comment"># Returns the contents of file2 and file3</span>
</pre>

<p>If <code>ARGV</code> is empty, <code>ARGF</code> acts as if it contained STDIN, i.e. the data piped to your script. For example:</p>

<pre>$ echo &quot;glark&quot; | ruby -e &#39;p ARGF.read&#39;
&quot;glark\n&quot;</pre>

  </section>

  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Instance Methods</h3>
       </header>

    
      <div id="method-i-argv" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            argv  &rarr; ARGV
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the <code>ARGV</code> array, which contains the arguments passed to your script, one per element.</p>

<p>For example:</p>

<pre>$ ruby argf.rb -v glark.txt

ARGF.argv   #=&gt; [&quot;-v&quot;, &quot;glark.txt&quot;]</pre>
          
          

          
          <div class="method-source-code" id="argv-source">
            <pre>static VALUE
argf_argv(VALUE argf)
{
    return ARGF.argv;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-binmode" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            binmode  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Puts <code>ARGF</code> into binary mode. Once a stream is in binary mode, it cannot be reset to non-binary mode. This option has the following effects:</p>
<ul><li>
<p>Newline conversion is disabled.</p>
</li><li>
<p><a href="Encoding.html"><code>Encoding</code></a> conversion is disabled.</p>
</li><li>
<p>Content is treated as ASCII-8BIT.</p>
</li></ul>
          
          

          
          <div class="method-source-code" id="binmode-source">
            <pre>static VALUE
argf_binmode_m(VALUE argf)
{
    ARGF.binmode = 1;
    next_argv();
    ARGF_FORWARD(0, 0);
    rb_io_ascii8bit_binmode(ARGF.current_file);
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-binmode-3F" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            binmode?  &rarr; true or false
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns true if <code>ARGF</code> is being read in binary mode; false otherwise. To enable binary mode use <code>ARGF.binmode</code>.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">binmode?</span>  <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">binmode</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">binmode?</span>  <span class="ruby-comment">#=&gt; true</span>
</pre>
          
          

          
          <div class="method-source-code" id="binmode-3F-source">
            <pre>static VALUE
argf_binmode_p(VALUE argf)
{
    return ARGF.binmode ? Qtrue : Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-bytes" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">bytes</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This is a deprecated alias for <a href="ARGF.html#method-i-each_byte"><code>each_byte</code></a>.</p>
          
          

          
          <div class="method-source-code" id="bytes-source">
            <pre>static VALUE
argf_bytes(VALUE argf)
{
    rb_warn_deprecated(&quot;ARGF#bytes&quot;, &quot;#each_byte&quot;);
    if (!rb_block_given_p())
        return rb_enumeratorize(argf, ID2SYM(rb_intern(&quot;each_byte&quot;)), 0, 0);
    return argf_each_byte(argf);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-chars" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">chars</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This is a deprecated alias for <a href="ARGF.html#method-i-each_char"><code>each_char</code></a>.</p>
          
          

          
          <div class="method-source-code" id="chars-source">
            <pre>static VALUE
argf_chars(VALUE argf)
{
    rb_warn_deprecated(&quot;ARGF#chars&quot;, &quot;#each_char&quot;);
    if (!rb_block_given_p())
        return rb_enumeratorize(argf, ID2SYM(rb_intern(&quot;each_char&quot;)), 0, 0);
    return argf_each_char(argf);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-close" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            close  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Closes the current file and skips to the next file in ARGV. If there are no more files to open, just closes the current file. <code>STDIN</code> will not be closed.</p>

<p>For example:</p>

<pre>$ ruby argf.rb foo bar

ARGF.filename  #=&gt; &quot;foo&quot;
ARGF.close
ARGF.filename  #=&gt; &quot;bar&quot;
ARGF.close</pre>
          
          

          
          <div class="method-source-code" id="close-source">
            <pre>static VALUE
argf_close_m(VALUE argf)
{
    next_argv();
    argf_close(argf);
    if (ARGF.next_p != -1) {
        ARGF.next_p = 1;
    }
    ARGF.lineno = 0;
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-closed-3F" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            closed?  &rarr; true or false
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns <em>true</em> if the current file has been closed; <em>false</em> otherwise. Use <code>ARGF.close</code> to actually close the current file.</p>
          
          

          
          <div class="method-source-code" id="closed-3F-source">
            <pre>static VALUE
argf_closed(VALUE argf)
{
    next_argv();
    ARGF_FORWARD(0, 0);
    return rb_io_closed(ARGF.current_file);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-codepoints" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">codepoints</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This is a deprecated alias for <a href="ARGF.html#method-i-each_codepoint"><code>each_codepoint</code></a>.</p>
          
          

          
          <div class="method-source-code" id="codepoints-source">
            <pre>static VALUE
argf_codepoints(VALUE argf)
{
    rb_warn_deprecated(&quot;ARGF#codepoints&quot;, &quot;#each_codepoint&quot;);
    if (!rb_block_given_p())
        return rb_enumeratorize(argf, ID2SYM(rb_intern(&quot;each_codepoint&quot;)), 0, 0);
    return argf_each_codepoint(argf);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-each" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            each(sep=$/)             {|line| block }  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each(sep=$/, limit)      {|line| block }  &rarr; ARGF
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each(...)                                 &rarr; an_enumerator
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_line(sep=$/)        {|line| block }  &rarr; ARGF
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_line(sep=$/, limit) {|line| block }  &rarr; ARGF
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_line(...)                            &rarr; an_enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns an enumerator which iterates over each line (separated by <em>sep</em>, which defaults to your platform&#39;s newline character) of each file in <code>ARGV</code>. If a block is supplied, each line in turn will be yielded to the block, otherwise an enumerator is returned. The optional <em>limit</em> argument is an <code>Integer</code> specifying the maximum length of each line; longer lines will be split according to this limit.</p>

<p>This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. After the last line of the first file has been returned, the first line of the second file is returned. The <code>ARGF.filename</code> and <code>ARGF.lineno</code> methods can be used to determine the filename of the current line and line number of the whole input, respectively.</p>

<p>For example, the following code prints out each line of each named file prefixed with its line number, displaying the filename once per file:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">filename</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">file</span>.<span class="ruby-identifier">lineno</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{ARGF.file.lineno}: #{line}&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<p>While the following code prints only the first file&#39;s name at first, and the contents with line number counted through all named files.</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">filename</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{ARGF.lineno}: #{line}&quot;</span>
<span class="ruby-keyword">end</span>
</pre>
          
          

          
          <div class="method-source-code" id="each-source">
            <pre>static VALUE
argf_each_line(int argc, VALUE *argv, VALUE argf)
{
    RETURN_ENUMERATOR(argf, argc, argv);
    FOREACH_ARGF() {
        argf_block_call_line(rb_intern(&quot;each_line&quot;), argc, argv, argf);
    }
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-each_byte" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            bytes     {|byte| block }  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            bytes                      &rarr; an_enumerator
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_byte {|byte| block }  &rarr; ARGF
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_byte                  &rarr; an_enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Iterates over each byte of each file in <code>ARGV</code>. A byte is returned as an <code>Integer</code> in the range 0..255.</p>

<p>This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. After the last byte of the first file has been returned, the first byte of the second file is returned. The <code>ARGF.filename</code> method can be used to determine the filename of the current byte.</p>

<p>If no block is given, an enumerator is returned instead.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">bytes</span>.<span class="ruby-identifier">to_a</span>  <span class="ruby-comment">#=&gt; [35, 32, ... 95, 10]</span>
</pre>
          
          

          
          <div class="method-source-code" id="each_byte-source">
            <pre>static VALUE
argf_each_byte(VALUE argf)
{
    RETURN_ENUMERATOR(argf, 0, 0);
    FOREACH_ARGF() {
        argf_block_call(rb_intern(&quot;each_byte&quot;), 0, 0, argf);
    }
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-each_char" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            each_char {|char| block }  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_char                  &rarr; an_enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Iterates over each character of each file in <code>ARGF</code>.</p>

<p>This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. After the last character of the first file has been returned, the first character of the second file is returned. The <code>ARGF.filename</code> method can be used to determine the name of the file in which the current character appears.</p>

<p>If no block is given, an enumerator is returned instead.</p>
          
          

          
          <div class="method-source-code" id="each_char-source">
            <pre>static VALUE
argf_each_char(VALUE argf)
{
    RETURN_ENUMERATOR(argf, 0, 0);
    FOREACH_ARGF() {
        argf_block_call(rb_intern(&quot;each_char&quot;), 0, 0, argf);
    }
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-each_codepoint" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            each_codepoint {|codepoint| block }  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_codepoint                       &rarr; an_enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Iterates over each codepoint of each file in <code>ARGF</code>.</p>

<p>This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. After the last codepoint of the first file has been returned, the first codepoint of the second file is returned. The <code>ARGF.filename</code> method can be used to determine the name of the file in which the current codepoint appears.</p>

<p>If no block is given, an enumerator is returned instead.</p>
          
          

          
          <div class="method-source-code" id="each_codepoint-source">
            <pre>static VALUE
argf_each_codepoint(VALUE argf)
{
    RETURN_ENUMERATOR(argf, 0, 0);
    FOREACH_ARGF() {
        argf_block_call(rb_intern(&quot;each_codepoint&quot;), 0, 0, argf);
    }
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-each_line" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            each_line(sep=$/)        {|line| block }  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_line(sep=$/, limit) {|line| block }  &rarr; ARGF
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_line(...)                            &rarr; an_enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns an enumerator which iterates over each line (separated by <em>sep</em>, which defaults to your platform&#39;s newline character) of each file in <code>ARGV</code>. If a block is supplied, each line in turn will be yielded to the block, otherwise an enumerator is returned. The optional <em>limit</em> argument is an <code>Integer</code> specifying the maximum length of each line; longer lines will be split according to this limit.</p>

<p>This method allows you to treat the files supplied on the command line as a single file consisting of the concatenation of each named file. After the last line of the first file has been returned, the first line of the second file is returned. The <code>ARGF.filename</code> and <code>ARGF.lineno</code> methods can be used to determine the filename of the current line and line number of the whole input, respectively.</p>

<p>For example, the following code prints out each line of each named file prefixed with its line number, displaying the filename once per file:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">filename</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">file</span>.<span class="ruby-identifier">lineno</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{ARGF.file.lineno}: #{line}&quot;</span>
<span class="ruby-keyword">end</span>
</pre>

<p>While the following code prints only the first file&#39;s name at first, and the contents with line number counted through all named files.</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">each_line</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">filename</span> <span class="ruby-keyword">if</span> <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;#{ARGF.lineno}: #{line}&quot;</span>
<span class="ruby-keyword">end</span>
</pre>
          
          

          
          <div class="method-source-code" id="each_line-source">
            <pre>static VALUE
argf_each_line(int argc, VALUE *argv, VALUE argf)
{
    RETURN_ENUMERATOR(argf, argc, argv);
    FOREACH_ARGF() {
        argf_block_call_line(rb_intern(&quot;each_line&quot;), argc, argv, argf);
    }
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-eof" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            eof?  &rarr; true or false
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            eof   &rarr; true or false
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns true if the current file in <code>ARGF</code> is at end of file, i.e. it has no data to read. The stream must be opened for reading or an <code>IOError</code> will be raised.</p>

<pre>$ echo &quot;eof&quot; | ruby argf.rb

ARGF.eof?                 #=&gt; false
3.times { ARGF.readchar }
ARGF.eof?                 #=&gt; false
ARGF.readchar             #=&gt; &quot;\n&quot;
ARGF.eof?                 #=&gt; true</pre>
          
          

          
          <div class="method-source-code" id="eof-source">
            <pre>static VALUE
argf_eof(VALUE argf)
{
    next_argv();
    if (RTEST(ARGF.current_file)) {
        if (ARGF.init_p == 0) return Qtrue;
        next_argv();
        ARGF_FORWARD(0, 0);
        if (rb_io_eof(ARGF.current_file)) {
            return Qtrue;
        }
    }
    return Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-eof-3F" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            eof?  &rarr; true or false
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns true if the current file in <code>ARGF</code> is at end of file, i.e. it has no data to read. The stream must be opened for reading or an <code>IOError</code> will be raised.</p>

<pre>$ echo &quot;eof&quot; | ruby argf.rb

ARGF.eof?                 #=&gt; false
3.times { ARGF.readchar }
ARGF.eof?                 #=&gt; false
ARGF.readchar             #=&gt; &quot;\n&quot;
ARGF.eof?                 #=&gt; true</pre>
          
          

          
          <div class="method-source-code" id="eof-3F-source">
            <pre>static VALUE
argf_eof(VALUE argf)
{
    next_argv();
    if (RTEST(ARGF.current_file)) {
        if (ARGF.init_p == 0) return Qtrue;
        next_argv();
        ARGF_FORWARD(0, 0);
        if (rb_io_eof(ARGF.current_file)) {
            return Qtrue;
        }
    }
    return Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-external_encoding" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            external_encoding   &rarr; encoding
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the external encoding for files read from <code>ARGF</code> as an <code>Encoding</code> object. The external encoding is the encoding of the text as stored in a file. Contrast with <code>ARGF.internal_encoding</code>, which is the encoding used to represent this text within Ruby.</p>

<p>To set the external encoding use <code>ARGF.set_encoding</code>.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">external_encoding</span>  <span class="ruby-comment">#=&gt;  #&lt;Encoding:UTF-8&gt;</span>
</pre>
          
          

          
          <div class="method-source-code" id="external_encoding-source">
            <pre>static VALUE
argf_external_encoding(VALUE argf)
{
    if (!RTEST(ARGF.current_file)) {
        return rb_enc_from_encoding(rb_default_external_encoding());
    }
    return rb_io_external_encoding(rb_io_check_io(ARGF.current_file));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-file" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            file  &rarr; IO or File object
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the current file as an <code>IO</code> or <code>File</code> object. <code>$stdin</code> is returned when the current file is STDIN.</p>

<p>For example:</p>

<pre>$ echo &quot;foo&quot; &gt; foo
$ echo &quot;bar&quot; &gt; bar

$ ruby argf.rb foo bar

ARGF.file      #=&gt; #&lt;File:foo&gt;
ARGF.read(5)   #=&gt; &quot;foo\nb&quot;
ARGF.file      #=&gt; #&lt;File:bar&gt;</pre>
          
          

          
          <div class="method-source-code" id="file-source">
            <pre>static VALUE
argf_file(VALUE argf)
{
    next_argv();
    return ARGF.current_file;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-filename" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            filename  &rarr; String
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the current filename. “-” is returned when the current file is STDIN.</p>

<p>For example:</p>

<pre>$ echo &quot;foo&quot; &gt; foo
$ echo &quot;bar&quot; &gt; bar
$ echo &quot;glark&quot; &gt; glark

$ ruby argf.rb foo bar glark

ARGF.filename  #=&gt; &quot;foo&quot;
ARGF.read(5)   #=&gt; &quot;foo\nb&quot;
ARGF.filename  #=&gt; &quot;bar&quot;
ARGF.skip
ARGF.filename  #=&gt; &quot;glark&quot;</pre>
          
          

          
          <div class="method-source-code" id="filename-source">
            <pre>static VALUE
argf_filename(VALUE argf)
{
    next_argv();
    return ARGF.filename;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-fileno" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            fileno    &rarr; integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns an integer representing the numeric file descriptor for the current file. Raises an <code>ArgumentError</code> if there isn&#39;t a current file.</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">fileno</span>    <span class="ruby-comment">#=&gt; 3</span>
</pre>
          
          

          
          <div class="method-source-code" id="fileno-source">
            <pre>static VALUE
argf_fileno(VALUE argf)
{
    if (!next_argv()) {
        rb_raise(rb_eArgError, &quot;no stream&quot;);
    }
    ARGF_FORWARD(0, 0);
    return rb_io_fileno(ARGF.current_file);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-getbyte" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            getbyte  &rarr; Integer or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Gets the next 8-bit byte (0..255) from <code>ARGF</code>. Returns <code>nil</code> if called at the end of the stream.</p>

<p>For example:</p>

<pre>$ echo &quot;foo&quot; &gt; file
$ ruby argf.rb file

ARGF.getbyte #=&gt; 102
ARGF.getbyte #=&gt; 111
ARGF.getbyte #=&gt; 111
ARGF.getbyte #=&gt; 10
ARGF.getbyte #=&gt; nil</pre>
          
          

          
          <div class="method-source-code" id="getbyte-source">
            <pre>static VALUE
argf_getbyte(VALUE argf)
{
    VALUE ch;

  retry:
    if (!next_argv()) return Qnil;
    if (!RB_TYPE_P(ARGF.current_file, T_FILE)) {
        ch = rb_funcall3(ARGF.current_file, rb_intern(&quot;getbyte&quot;), 0, 0);
    }
    else {
        ch = rb_io_getbyte(ARGF.current_file);
    }
    if (NIL_P(ch) &amp;&amp; ARGF.next_p != -1) {
        argf_close(argf);
        ARGF.next_p = 1;
        goto retry;
    }

    return ch;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-getc" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            getc  &rarr; String or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reads the next character from <code>ARGF</code> and returns it as a <code>String</code>. Returns <code>nil</code> at the end of the stream.</p>

<p><code>ARGF</code> treats the files named on the command line as a single file created by concatenating their contents. After returning the last character of the first file, it returns the first character of the second file, and so on.</p>

<p>For example:</p>

<pre>$ echo &quot;foo&quot; &gt; file
$ ruby argf.rb file

ARGF.getc  #=&gt; &quot;f&quot;
ARGF.getc  #=&gt; &quot;o&quot;
ARGF.getc  #=&gt; &quot;o&quot;
ARGF.getc  #=&gt; &quot;\n&quot;
ARGF.getc  #=&gt; nil
ARGF.getc  #=&gt; nil</pre>
          
          

          
          <div class="method-source-code" id="getc-source">
            <pre>static VALUE
argf_getc(VALUE argf)
{
    VALUE ch;

  retry:
    if (!next_argv()) return Qnil;
    if (ARGF_GENERIC_INPUT_P()) {
        ch = rb_funcall3(ARGF.current_file, rb_intern(&quot;getc&quot;), 0, 0);
    }
    else {
        ch = rb_io_getc(ARGF.current_file);
    }
    if (NIL_P(ch) &amp;&amp; ARGF.next_p != -1) {
        argf_close(argf);
        ARGF.next_p = 1;
        goto retry;
    }

    return ch;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-gets" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            gets(sep=$/ [, getline_args])     &rarr; string or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gets(limit [, getline_args])      &rarr; string or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gets(sep, limit [, getline_args]) &rarr; string or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the next line from the current file in <code>ARGF</code>.</p>

<p>By default lines are assumed to be separated by <code>$/</code>; to use a different character as a separator, supply it as a <code>String</code> for the <em>sep</em> argument.</p>

<p>The optional <em>limit</em> argument specifies how many characters of each line to return. By default all characters are returned.</p>

<p>See <a href="IO.html#method-c-readlines"><code>IO.readlines</code></a> for details about getline_args.</p>
          
          

          
          <div class="method-source-code" id="gets-source">
            <pre>static VALUE
argf_gets(int argc, VALUE *argv, VALUE argf)
{
    VALUE line;

    line = argf_getline(argc, argv, argf);
    rb_lastline_set(line);

    return line;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-inplace_mode" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            inplace_mode  &rarr; String
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the file extension appended to the names of modified files under in-place edit mode. This value can be set using <code>ARGF.inplace_mode=</code> or passing the <code>-i</code> switch to the Ruby binary.</p>
          
          

          
          <div class="method-source-code" id="inplace_mode-source">
            <pre>static VALUE
argf_inplace_mode_get(VALUE argf)
{
    if (!ARGF.inplace) return Qnil;
    if (NIL_P(ARGF.inplace)) return rb_str_new(0, 0);
    return rb_str_dup(ARGF.inplace);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-inplace_mode-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            inplace_mode = ext  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the filename extension for in-place editing mode to the given <a href="String.html"><code>String</code></a>. Each file being edited has this value appended to its filename. The modified file is saved under this new name.</p>

<p>For example:</p>

<pre>$ ruby argf.rb file.txt

ARGF.inplace_mode = &#39;.bak&#39;
ARGF.each_line do |line|
  print line.sub(&quot;foo&quot;,&quot;bar&quot;)
end</pre>

<p>Each line of <em>file.txt</em> has the first occurrence of “foo” replaced with “bar”, then the new line is written out to <em>file.txt.bak</em>.</p>
          
          

          
          <div class="method-source-code" id="inplace_mode-3D-source">
            <pre>static VALUE
argf_inplace_mode_set(VALUE argf, VALUE val)
{
    if (!RTEST(val)) {
        ARGF.inplace = Qfalse;
    }
    else if (StringValueCStr(val), !RSTRING_LEN(val)) {
        ARGF.inplace = Qnil;
    }
    else {
        ARGF.inplace = rb_str_new_frozen(val);
    }
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-inspect" class="method-detail method-alias">
        
        <div class="method-heading">
          <span class="method-name">inspect</span><span
            class="method-args">()</span>
          
        </div>
        

        <div class="method-description">
          
          
          
          

          
        </div>

        

        
        <div class="aliases">
          Alias for: <a href="ARGF.html#method-i-to_s">to_s</a>
        </div>
        
      </div>

    
      <div id="method-i-internal_encoding" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            internal_encoding   &rarr; encoding
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the internal encoding for strings read from <code>ARGF</code> as an <code>Encoding</code> object.</p>

<p>If <code>ARGF.set_encoding</code> has been called with two encoding names, the second is returned. Otherwise, if <code>Encoding.default_external</code> has been set, that value is returned. Failing that, if a default external encoding was specified on the command-line, that value is used. If the encoding is unknown, <code>nil</code> is returned.</p>
          
          

          
          <div class="method-source-code" id="internal_encoding-source">
            <pre>static VALUE
argf_internal_encoding(VALUE argf)
{
    if (!RTEST(ARGF.current_file)) {
        return rb_enc_from_encoding(rb_default_external_encoding());
    }
    return rb_io_internal_encoding(rb_io_check_io(ARGF.current_file));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-lineno" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            lineno  &rarr; integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the current line number of <a href="ARGF.html"><code>ARGF</code></a> as a whole. This value can be set manually with <code>ARGF.lineno=</code>.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span>   <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">readline</span> <span class="ruby-comment">#=&gt; &quot;This is line 1\n&quot;</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span>   <span class="ruby-comment">#=&gt; 1</span>
</pre>
          
          

          
          <div class="method-source-code" id="lineno-source">
            <pre>static VALUE
argf_lineno(VALUE argf)
{
    return INT2FIX(ARGF.lineno);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-lineno-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            lineno = integer  &rarr; integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the line number of <code>ARGF</code> as a whole to the given <code>Integer</code>.</p>

<p><code>ARGF</code> sets the line number automatically as you read data, so normally you will not need to set it explicitly. To access the current line number use <code>ARGF.lineno</code>.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span>      <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">readline</span>    <span class="ruby-comment">#=&gt; &quot;This is line 1\n&quot;</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span>      <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span> = <span class="ruby-value">0</span>  <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span>      <span class="ruby-comment">#=&gt; 0</span>
</pre>
          
          

          
          <div class="method-source-code" id="lineno-3D-source">
            <pre>static VALUE
argf_set_lineno(VALUE argf, VALUE val)
{
    ARGF.lineno = NUM2INT(val);
    ARGF.last_lineno = ARGF.lineno;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-lines" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">lines</span><span
            class="method-args">(*args)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>This is a deprecated alias for <a href="ARGF.html#method-i-each_line"><code>each_line</code></a>.</p>
          
          

          
          <div class="method-source-code" id="lines-source">
            <pre>static VALUE
argf_lines(int argc, VALUE *argv, VALUE argf)
{
    rb_warn_deprecated(&quot;ARGF#lines&quot;, &quot;#each_line&quot;);
    if (!rb_block_given_p())
        return rb_enumeratorize(argf, ID2SYM(rb_intern(&quot;each_line&quot;)), argc, argv);
    return argf_each_line(argc, argv, argf);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-path" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            path      &rarr; String
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the current filename. “-” is returned when the current file is STDIN.</p>

<p>For example:</p>

<pre>$ echo &quot;foo&quot; &gt; foo
$ echo &quot;bar&quot; &gt; bar
$ echo &quot;glark&quot; &gt; glark

$ ruby argf.rb foo bar glark

ARGF.filename  #=&gt; &quot;foo&quot;
ARGF.read(5)   #=&gt; &quot;foo\nb&quot;
ARGF.filename  #=&gt; &quot;bar&quot;
ARGF.skip
ARGF.filename  #=&gt; &quot;glark&quot;</pre>
          
          

          
          <div class="method-source-code" id="path-source">
            <pre>static VALUE
argf_filename(VALUE argf)
{
    next_argv();
    return ARGF.filename;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-pos" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            pos   &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the current offset (in bytes) of the current file in <code>ARGF</code>.</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">pos</span>    <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">gets</span>   <span class="ruby-comment">#=&gt; &quot;This is line one\n&quot;</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">pos</span>    <span class="ruby-comment">#=&gt; 17</span>
</pre>
          
          

          
          <div class="method-source-code" id="pos-source">
            <pre>static VALUE
argf_tell(VALUE argf)
{
    if (!next_argv()) {
        rb_raise(rb_eArgError, &quot;no stream to tell&quot;);
    }
    ARGF_FORWARD(0, 0);
    return rb_io_tell(ARGF.current_file);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-pos-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            pos = position  &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Seeks to the position given by <em>position</em> (in bytes) in <code>ARGF</code>.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">pos</span> = <span class="ruby-value">17</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">gets</span>   <span class="ruby-comment">#=&gt; &quot;This is line two\n&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="pos-3D-source">
            <pre>static VALUE
argf_set_pos(VALUE argf, VALUE offset)
{
    if (!next_argv()) {
        rb_raise(rb_eArgError, &quot;no stream to set position&quot;);
    }
    ARGF_FORWARD(1, &amp;offset);
    return rb_io_set_pos(ARGF.current_file, offset);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-print" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            print               &rarr; nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            print(obj, ...)     &rarr; nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Writes the given object(s) to <em>ios</em>. Returns <code>nil</code>.</p>

<p>The stream must be opened for writing. Each given object that isn&#39;t a string will be converted by calling its <code>to_s</code> method. When called without arguments, prints the contents of <code>$_</code>.</p>

<p>If the output field separator (<code>$,</code>) is not <code>nil</code>, it is inserted between objects. If the output record separator (<code>$\</code>) is not <code>nil</code>, it is appended to the output.</p>

<pre class="ruby"><span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">print</span>(<span class="ruby-string">&quot;This is &quot;</span>, <span class="ruby-value">100</span>, <span class="ruby-string">&quot; percent.\n&quot;</span>)
</pre>

<p><em>produces:</em></p>

<pre>This is 100 percent.</pre>
          
          

          
          <div class="method-source-code" id="print-source">
            <pre>VALUE
rb_io_print(int argc, const VALUE *argv, VALUE out)
{
    int i;
    VALUE line;

    /* if no argument given, print `$_&#39; */
    if (argc == 0) {
        argc = 1;
        line = rb_lastline_get();
        argv = &amp;line;
    }
    for (i=0; i&lt;argc; i++) {
        if (!NIL_P(rb_output_fs) &amp;&amp; i&gt;0) {
            rb_io_write(out, rb_output_fs);
        }
        rb_io_write(out, argv[i]);
    }
    if (argc &gt; 0 &amp;&amp; !NIL_P(rb_output_rs)) {
        rb_io_write(out, rb_output_rs);
    }

    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-printf" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            printf(format_string [, obj, ...])   &rarr; nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Formats and writes to <em>ios</em>, converting parameters under control of the format string. See <a href="Kernel.html#method-i-sprintf"><code>Kernel#sprintf</code></a> for details.</p>
          
          

          
          <div class="method-source-code" id="printf-source">
            <pre>VALUE
rb_io_printf(int argc, const VALUE *argv, VALUE out)
{
    rb_io_write(out, rb_f_sprintf(argc, argv));
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-putc" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            putc(obj)    &rarr; obj
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>If <em>obj</em> is <a href="Numeric.html"><code>Numeric</code></a>, write the character whose code is the least-significant byte of <em>obj</em>.  If <em>obj</em> is <a href="String.html"><code>String</code></a>, write the first character of <em>obj</em> to <em>ios</em>.  Otherwise, raise <a href="TypeError.html"><code>TypeError</code></a>.</p>

<pre class="ruby"><span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">putc</span> <span class="ruby-string">&quot;A&quot;</span>
<span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">putc</span> <span class="ruby-value">65</span>
</pre>

<p><em>produces:</em></p>

<pre class="ruby"><span class="ruby-constant">AA</span>
</pre>
          
          

          
          <div class="method-source-code" id="putc-source">
            <pre>static VALUE
rb_io_putc(VALUE io, VALUE ch)
{
    VALUE str;
    if (RB_TYPE_P(ch, T_STRING)) {
        str = rb_str_substr(ch, 0, 1);
    }
    else {
        char c = NUM2CHR(ch);
        str = rb_str_new(&amp;c, 1);
    }
    rb_io_write(io, str);
    return ch;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-puts" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            puts(obj, ...)    &rarr; nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Writes the given object(s) to <em>ios</em>. Writes a newline after any that do not already end with a newline sequence. Returns <code>nil</code>.</p>

<p>The stream must be opened for writing. If called with an array argument, writes each element on a new line. Each given object that isn&#39;t a string or array will be converted by calling its <code>to_s</code> method. If called without arguments, outputs a single newline.</p>

<pre class="ruby"><span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-string">&quot;this&quot;</span>, <span class="ruby-string">&quot;is&quot;</span>, [<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-string">&quot;test&quot;</span>])
</pre>

<p><em>produces:</em></p>

<pre class="ruby"><span class="ruby-identifier">this</span>
<span class="ruby-identifier">is</span>
<span class="ruby-identifier">a</span>
<span class="ruby-identifier">test</span>
</pre>

<p>Note that <code>puts</code> always uses newlines and is not affected by the output record separator (<code>$\</code>).</p>
          
          

          
          <div class="method-source-code" id="puts-source">
            <pre>VALUE
rb_io_puts(int argc, const VALUE *argv, VALUE out)
{
    int i, n;
    VALUE line, args[2];

    /* if no argument given, print newline. */
    if (argc == 0) {
        rb_io_write(out, rb_default_rs);
        return Qnil;
    }
    for (i=0; i&lt;argc; i++) {
        if (RB_TYPE_P(argv[i], T_STRING)) {
            line = argv[i];
            goto string;
        }
        if (rb_exec_recursive(io_puts_ary, argv[i], out)) {
            continue;
        }
        line = rb_obj_as_string(argv[i]);
      string:
        n = 0;
        args[n++] = line;
        if (RSTRING_LEN(line) == 0 ||
            !rb_str_end_with_asciichar(line, &#39;\n&#39;)) {
            args[n++] = rb_default_rs;
        }
        rb_io_writev(out, n, args);
    }

    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-read" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            read([length [, outbuf]])    &rarr; string, outbuf, or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reads <em>length</em> bytes from <a href="ARGF.html"><code>ARGF</code></a>. The files named on the command line are concatenated and treated as a single file by this method, so when called without arguments the contents of this pseudo file are returned in their entirety.</p>

<p><em>length</em> must be a non-negative integer or <code>nil</code>.</p>

<p>If <em>length</em> is a positive integer, <code>read</code> tries to read <em>length</em> bytes without any conversion (binary mode). It returns <code>nil</code> if an EOF is encountered before anything can be read. Fewer than <em>length</em> bytes are returned if an EOF is encountered during the read. In the case of an integer <em>length</em>, the resulting string is always in ASCII-8BIT encoding.</p>

<p>If <em>length</em> is omitted or is <code>nil</code>, it reads until EOF and the encoding conversion is applied, if applicable. A string is returned even if EOF is encountered before any data is read.</p>

<p>If <em>length</em> is zero, it returns an empty string (<code>&quot;&quot;</code>).</p>

<p>If the optional <em>outbuf</em> argument is present, it must reference a <a href="String.html"><code>String</code></a>, which will receive the data. The <em>outbuf</em> will contain only the received data after the method call even if it is not empty at the beginning.</p>

<p>For example:</p>

<pre>$ echo &quot;small&quot; &gt; small.txt
$ echo &quot;large&quot; &gt; large.txt
$ ./glark.rb small.txt large.txt

ARGF.read      #=&gt; &quot;small\nlarge&quot;
ARGF.read(200) #=&gt; &quot;small\nlarge&quot;
ARGF.read(2)   #=&gt; &quot;sm&quot;
ARGF.read(0)   #=&gt; &quot;&quot;</pre>

<p>Note that this method behaves like the fread() function in C. This means it retries to invoke read(2) system calls to read data with the specified length. If you need the behavior like a single read(2) system call, consider <a href="ARGF.html#method-i-readpartial"><code>ARGF#readpartial</code></a> or <a href="ARGF.html#method-i-read_nonblock"><code>ARGF#read_nonblock</code></a>.</p>
          
          

          
          <div class="method-source-code" id="read-source">
            <pre>static VALUE
argf_read(int argc, VALUE *argv, VALUE argf)
{
    VALUE tmp, str, length;
    long len = 0;

    rb_scan_args(argc, argv, &quot;02&quot;, &amp;length, &amp;str);
    if (!NIL_P(length)) {
        len = NUM2LONG(argv[0]);
    }
    if (!NIL_P(str)) {
        StringValue(str);
        rb_str_resize(str,0);
        argv[1] = Qnil;
    }

  retry:
    if (!next_argv()) {
        return str;
    }
    if (ARGF_GENERIC_INPUT_P()) {
        tmp = argf_forward(argc, argv, argf);
    }
    else {
        tmp = io_read(argc, argv, ARGF.current_file);
    }
    if (NIL_P(str)) str = tmp;
    else if (!NIL_P(tmp)) rb_str_append(str, tmp);
    if (NIL_P(tmp) || NIL_P(length)) {
        if (ARGF.next_p != -1) {
            argf_close(argf);
            ARGF.next_p = 1;
            goto retry;
        }
    }
    else if (argc &gt;= 1) {
        long slen = RSTRING_LEN(str);
        if (slen &lt; len) {
            len -= slen;
            argv[0] = INT2NUM(len);
            goto retry;
        }
    }
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-read_nonblock" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            read_nonblock(maxlen[, options])              &rarr; string
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            read_nonblock(maxlen, outbuf[, options])      &rarr; outbuf
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reads at most <em>maxlen</em> bytes from the <a href="ARGF.html"><code>ARGF</code></a> stream in non-blocking mode.</p>
          
          

          
          <div class="method-source-code" id="read_nonblock-source">
            <pre>static VALUE
argf_read_nonblock(int argc, VALUE *argv, VALUE argf)
{
    VALUE opts;

    rb_scan_args(argc, argv, &quot;11:&quot;, NULL, NULL, &amp;opts);

    if (!NIL_P(opts))
        argc--;

    return argf_getpartial(argc, argv, argf, opts, 1);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-readbyte" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            readbyte  &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reads the next 8-bit byte from <a href="ARGF.html"><code>ARGF</code></a> and returns it as an <code>Integer</code>. Raises an <code>EOFError</code> after the last byte of the last file has been read.</p>

<p>For example:</p>

<pre>$ echo &quot;foo&quot; &gt; file
$ ruby argf.rb file

ARGF.readbyte  #=&gt; 102
ARGF.readbyte  #=&gt; 111
ARGF.readbyte  #=&gt; 111
ARGF.readbyte  #=&gt; 10
ARGF.readbyte  #=&gt; end of file reached (EOFError)</pre>
          
          

          
          <div class="method-source-code" id="readbyte-source">
            <pre>static VALUE
argf_readbyte(VALUE argf)
{
    VALUE c;

    NEXT_ARGF_FORWARD(0, 0);
    c = argf_getbyte(argf);
    if (NIL_P(c)) {
        rb_eof_error();
    }
    return c;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-readchar" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            readchar  &rarr; String or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reads the next character from <code>ARGF</code> and returns it as a <code>String</code>. Raises an <code>EOFError</code> after the last character of the last file has been read.</p>

<p>For example:</p>

<pre>$ echo &quot;foo&quot; &gt; file
$ ruby argf.rb file

ARGF.readchar  #=&gt; &quot;f&quot;
ARGF.readchar  #=&gt; &quot;o&quot;
ARGF.readchar  #=&gt; &quot;o&quot;
ARGF.readchar  #=&gt; &quot;\n&quot;
ARGF.readchar  #=&gt; end of file reached (EOFError)</pre>
          
          

          
          <div class="method-source-code" id="readchar-source">
            <pre>static VALUE
argf_readchar(VALUE argf)
{
    VALUE ch;

  retry:
    if (!next_argv()) rb_eof_error();
    if (!RB_TYPE_P(ARGF.current_file, T_FILE)) {
        ch = rb_funcall3(ARGF.current_file, rb_intern(&quot;getc&quot;), 0, 0);
    }
    else {
        ch = rb_io_getc(ARGF.current_file);
    }
    if (NIL_P(ch) &amp;&amp; ARGF.next_p != -1) {
        argf_close(argf);
        ARGF.next_p = 1;
        goto retry;
    }

    return ch;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-readline" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            readline(sep=$/)     &rarr; string
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            readline(limit)      &rarr; string
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            readline(sep, limit) &rarr; string
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the next line from the current file in <code>ARGF</code>.</p>

<p>By default lines are assumed to be separated by <code>$/</code>; to use a different character as a separator, supply it as a <code>String</code> for the <em>sep</em> argument.</p>

<p>The optional <em>limit</em> argument specifies how many characters of each line to return. By default all characters are returned.</p>

<p>An <code>EOFError</code> is raised at the end of the file.</p>
          
          

          
          <div class="method-source-code" id="readline-source">
            <pre>static VALUE
argf_readline(int argc, VALUE *argv, VALUE argf)
{
    VALUE line;

    if (!next_argv()) rb_eof_error();
    ARGF_FORWARD(argc, argv);
    line = argf_gets(argc, argv, argf);
    if (NIL_P(line)) {
        rb_eof_error();
    }

    return line;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-readlines" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            readlines(sep=$/)     &rarr; array
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            readlines(limit)      &rarr; array
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            readlines(sep, limit) &rarr; array
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reads <code>ARGF</code>&#39;s current file in its entirety, returning an <code>Array</code> of its lines, one line per element. Lines are assumed to be separated by <em>sep</em>.</p>

<pre class="ruby"><span class="ruby-identifier">lines</span> = <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">readlines</span>
<span class="ruby-identifier">lines</span>[<span class="ruby-value">0</span>]                <span class="ruby-comment">#=&gt; &quot;This is line one\n&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="readlines-source">
            <pre>static VALUE
argf_readlines(int argc, VALUE *argv, VALUE argf)
{
    long lineno = ARGF.lineno;
    VALUE lines, ary;

    ary = rb_ary_new();
    while (next_argv()) {
        if (ARGF_GENERIC_INPUT_P()) {
            lines = rb_funcall3(ARGF.current_file, rb_intern(&quot;readlines&quot;), argc, argv);
        }
        else {
            lines = rb_io_readlines(argc, argv, ARGF.current_file);
            argf_close(argf);
        }
        ARGF.next_p = 1;
        rb_ary_concat(ary, lines);
        ARGF.lineno = lineno + RARRAY_LEN(ary);
        ARGF.last_lineno = ARGF.lineno;
    }
    ARGF.init_p = 0;
    return ary;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-readpartial" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            readpartial(maxlen)              &rarr; string
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            readpartial(maxlen, outbuf)      &rarr; outbuf
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reads at most <em>maxlen</em> bytes from the <a href="ARGF.html"><code>ARGF</code></a> stream.</p>

<p>If the optional <em>outbuf</em> argument is present, it must reference a <a href="String.html"><code>String</code></a>, which will receive the data. The <em>outbuf</em> will contain only the received data after the method call even if it is not empty at the beginning.</p>

<p>It raises <a href="EOFError.html"><code>EOFError</code></a> on end of <a href="ARGF.html"><code>ARGF</code></a> stream. Since <a href="ARGF.html"><code>ARGF</code></a> stream is a concatenation of multiple files, internally EOF is occur for each file. <a href="ARGF.html#method-i-readpartial"><code>ARGF.readpartial</code></a> returns empty strings for EOFs except the last one and raises <a href="EOFError.html"><code>EOFError</code></a> for the last one.</p>
          
          

          
          <div class="method-source-code" id="readpartial-source">
            <pre>static VALUE
argf_readpartial(int argc, VALUE *argv, VALUE argf)
{
    return argf_getpartial(argc, argv, argf, Qnil, 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-rewind" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            rewind   &rarr; 0
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Positions the current file to the beginning of input, resetting <code>ARGF.lineno</code> to zero.</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">readline</span>   <span class="ruby-comment">#=&gt; &quot;This is line one\n&quot;</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">rewind</span>     <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">lineno</span>     <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">readline</span>   <span class="ruby-comment">#=&gt; &quot;This is line one\n&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="rewind-source">
            <pre>static VALUE
argf_rewind(VALUE argf)
{
    VALUE ret;
    int old_lineno;

    if (!next_argv()) {
        rb_raise(rb_eArgError, &quot;no stream to rewind&quot;);
    }
    ARGF_FORWARD(0, 0);
    old_lineno = RFILE(ARGF.current_file)-&gt;fptr-&gt;lineno;
    ret = rb_io_rewind(ARGF.current_file);
    if (!global_argf_p(argf)) {
        ARGF.last_lineno = ARGF.lineno -= old_lineno;
    }
    return ret;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-seek" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            seek(amount, whence=IO::SEEK_SET)  &rarr; 0
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Seeks to offset <em>amount</em> (an <code>Integer</code>) in the <code>ARGF</code> stream according to the value of <em>whence</em>. See <a href="IO.html#method-i-seek"><code>IO#seek</code></a> for further details.</p>
          
          

          
          <div class="method-source-code" id="seek-source">
            <pre>static VALUE
argf_seek_m(int argc, VALUE *argv, VALUE argf)
{
    if (!next_argv()) {
        rb_raise(rb_eArgError, &quot;no stream to seek&quot;);
    }
    ARGF_FORWARD(argc, argv);
    return rb_io_seek_m(argc, argv, ARGF.current_file);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-set_encoding" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            set_encoding(ext_enc)                &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            set_encoding(&quot;ext_enc:int_enc&quot;)      &rarr; ARGF
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            set_encoding(ext_enc, int_enc)       &rarr; ARGF
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            set_encoding(&quot;ext_enc:int_enc&quot;, opt) &rarr; ARGF
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            set_encoding(ext_enc, int_enc, opt)  &rarr; ARGF
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>If single argument is specified, strings read from <a href="ARGF.html"><code>ARGF</code></a> are tagged with the encoding specified.</p>

<p>If two encoding names separated by a colon are given, e.g. “ascii:utf-8”, the read string is converted from the first encoding (external encoding) to the second encoding (internal encoding), then tagged with the second encoding.</p>

<p>If two arguments are specified, they must be encoding objects or encoding names. Again, the first specifies the external encoding; the second specifies the internal encoding.</p>

<p>If the external encoding and the internal encoding are specified, the optional <code>Hash</code> argument can be used to adjust the conversion process. The structure of this hash is explained in the <a href="String.html#method-i-encode"><code>String#encode</code></a> documentation.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">set_encoding</span>(<span class="ruby-string">&#39;ascii&#39;</span>)         <span class="ruby-comment"># Tag the input as US-ASCII text</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">set_encoding</span>(<span class="ruby-constant">Encoding</span><span class="ruby-operator">::</span><span class="ruby-constant">UTF_8</span>) <span class="ruby-comment"># Tag the input as UTF-8 text</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">set_encoding</span>(<span class="ruby-string">&#39;utf-8&#39;</span>,<span class="ruby-string">&#39;ascii&#39;</span>) <span class="ruby-comment"># Transcode the input from US-ASCII</span>
                                   <span class="ruby-comment"># to UTF-8.</span>
</pre>
          
          

          
          <div class="method-source-code" id="set_encoding-source">
            <pre>static VALUE
argf_set_encoding(int argc, VALUE *argv, VALUE argf)
{
    rb_io_t *fptr;

    if (!next_argv()) {
        rb_raise(rb_eArgError, &quot;no stream to set encoding&quot;);
    }
    rb_io_set_encoding(argc, argv, ARGF.current_file);
    GetOpenFile(ARGF.current_file, fptr);
    ARGF.encs = fptr-&gt;encs;
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-skip" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            skip  &rarr; ARGF
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Sets the current file to the next file in ARGV. If there aren&#39;t any more files it has no effect.</p>

<p>For example:</p>

<pre>$ ruby argf.rb foo bar
ARGF.filename  #=&gt; &quot;foo&quot;
ARGF.skip
ARGF.filename  #=&gt; &quot;bar&quot;</pre>
          
          

          
          <div class="method-source-code" id="skip-source">
            <pre>static VALUE
argf_skip(VALUE argf)
{
    if (ARGF.init_p &amp;&amp; ARGF.next_p == 0) {
        argf_close(argf);
        ARGF.next_p = 1;
    }
    return argf;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-tell" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            tell  &rarr; Integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the current offset (in bytes) of the current file in <code>ARGF</code>.</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">pos</span>    <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">gets</span>   <span class="ruby-comment">#=&gt; &quot;This is line one\n&quot;</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">pos</span>    <span class="ruby-comment">#=&gt; 17</span>
</pre>
          
          

          
          <div class="method-source-code" id="tell-source">
            <pre>static VALUE
argf_tell(VALUE argf)
{
    if (!next_argv()) {
        rb_raise(rb_eArgError, &quot;no stream to tell&quot;);
    }
    ARGF_FORWARD(0, 0);
    return rb_io_tell(ARGF.current_file);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-to_a" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            to_a(sep=$/)     &rarr; array
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            to_a(limit)      &rarr; array
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            to_a(sep, limit) &rarr; array
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reads <code>ARGF</code>&#39;s current file in its entirety, returning an <code>Array</code> of its lines, one line per element. Lines are assumed to be separated by <em>sep</em>.</p>

<pre class="ruby"><span class="ruby-identifier">lines</span> = <span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">readlines</span>
<span class="ruby-identifier">lines</span>[<span class="ruby-value">0</span>]                <span class="ruby-comment">#=&gt; &quot;This is line one\n&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="to_a-source">
            <pre>static VALUE
argf_readlines(int argc, VALUE *argv, VALUE argf)
{
    long lineno = ARGF.lineno;
    VALUE lines, ary;

    ary = rb_ary_new();
    while (next_argv()) {
        if (ARGF_GENERIC_INPUT_P()) {
            lines = rb_funcall3(ARGF.current_file, rb_intern(&quot;readlines&quot;), argc, argv);
        }
        else {
            lines = rb_io_readlines(argc, argv, ARGF.current_file);
            argf_close(argf);
        }
        ARGF.next_p = 1;
        rb_ary_concat(ary, lines);
        ARGF.lineno = lineno + RARRAY_LEN(ary);
        ARGF.last_lineno = ARGF.lineno;
    }
    ARGF.init_p = 0;
    return ary;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-to_i" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            to_i      &rarr; integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns an integer representing the numeric file descriptor for the current file. Raises an <code>ArgumentError</code> if there isn&#39;t a current file.</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">fileno</span>    <span class="ruby-comment">#=&gt; 3</span>
</pre>
          
          

          
          <div class="method-source-code" id="to_i-source">
            <pre>static VALUE
argf_fileno(VALUE argf)
{
    if (!next_argv()) {
        rb_raise(rb_eArgError, &quot;no stream&quot;);
    }
    ARGF_FORWARD(0, 0);
    return rb_io_fileno(ARGF.current_file);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-to_io" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            to_io     &rarr; IO
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns an <code>IO</code> object representing the current file. This will be a <code>File</code> object unless the current file is a stream such as STDIN.</p>

<p>For example:</p>

<pre class="ruby"><span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">to_io</span>    <span class="ruby-comment">#=&gt; #&lt;File:glark.txt&gt;</span>
<span class="ruby-constant">ARGF</span>.<span class="ruby-identifier">to_io</span>    <span class="ruby-comment">#=&gt; #&lt;IO:&lt;STDIN&gt;&gt;</span>
</pre>
          
          

          
          <div class="method-source-code" id="to_io-source">
            <pre>static VALUE
argf_to_io(VALUE argf)
{
    next_argv();
    ARGF_FORWARD(0, 0);
    return ARGF.current_file;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-to_s" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            to_s  &rarr; String
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns “ARGF”.</p>
          
          

          
          <div class="method-source-code" id="to_s-source">
            <pre>static VALUE
argf_to_s(VALUE argf)
{
    return rb_str_new2(&quot;ARGF&quot;);
}</pre>
          </div>
          
        </div>

        
        <div class="aliases">
          Also aliased as: <a href="ARGF.html#method-i-inspect">inspect</a>
        </div>
        

        
      </div>

    
      <div id="method-i-to_write_io" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            to_write_io  &rarr; io
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns <a href="IO.html"><code>IO</code></a> instance tied to <em>ARGF</em> for writing if inplace mode is enabled.</p>
          
          

          
          <div class="method-source-code" id="to_write_io-source">
            <pre>static VALUE
argf_write_io(VALUE argf)
{
    if (!RTEST(ARGF.current_file)) {
        rb_raise(rb_eIOError, &quot;not opened for writing&quot;);
    }
    return GetWriteIO(ARGF.current_file);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-write" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            write(string)   &rarr; integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Writes <em>string</em> if inplace mode.</p>
          
          

          
          <div class="method-source-code" id="write-source">
            <pre>static VALUE
argf_write(VALUE argf, VALUE str)
{
    return rb_io_write(argf_write_io(argf), str);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>

</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>