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/StringIO.html
<!DOCTYPE html>

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

<title>class StringIO - 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="Data.html">Data</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>
  
  
  
    <li><a class="include" href="IO/generic_readable.html">IO::generic_readable</a>
  
  
  
    <li><a class="include" href="IO/generic_writable.html">IO::generic_writable</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-c-new">::new</a>
    
    <li ><a href="#method-c-open">::open</a>
    
    <li ><a href="#method-i-binmode">#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-close_read">#close_read</a>
    
    <li ><a href="#method-i-close_write">#close_write</a>
    
    <li ><a href="#method-i-closed-3F">#closed?</a>
    
    <li ><a href="#method-i-closed_read-3F">#closed_read?</a>
    
    <li ><a href="#method-i-closed_write-3F">#closed_write?</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-fcntl">#fcntl</a>
    
    <li ><a href="#method-i-fileno">#fileno</a>
    
    <li ><a href="#method-i-flush">#flush</a>
    
    <li ><a href="#method-i-fsync">#fsync</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-internal_encoding">#internal_encoding</a>
    
    <li ><a href="#method-i-isatty">#isatty</a>
    
    <li ><a href="#method-i-length">#length</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-pid">#pid</a>
    
    <li ><a href="#method-i-pos">#pos</a>
    
    <li ><a href="#method-i-pos-3D">#pos=</a>
    
    <li ><a href="#method-i-putc">#putc</a>
    
    <li ><a href="#method-i-read">#read</a>
    
    <li ><a href="#method-i-readlines">#readlines</a>
    
    <li ><a href="#method-i-reopen">#reopen</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-set_encoding_by_bom">#set_encoding_by_bom</a>
    
    <li ><a href="#method-i-size">#size</a>
    
    <li ><a href="#method-i-string">#string</a>
    
    <li ><a href="#method-i-string-3D">#string=</a>
    
    <li ><a href="#method-i-sync">#sync</a>
    
    <li ><a href="#method-i-sync-3D">#sync=</a>
    
    <li ><a href="#method-i-tell">#tell</a>
    
    <li ><a href="#method-i-truncate">#truncate</a>
    
    <li ><a href="#method-i-tty-3F">#tty?</a>
    
    <li ><a href="#method-i-ungetbyte">#ungetbyte</a>
    
    <li ><a href="#method-i-ungetc">#ungetc</a>
    
    <li ><a href="#method-i-write">#write</a>
    
  </ul>
</div>

  </div>
</nav>

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

  <section class="description">
    
<p>Pseudo I/O on <a href="String.html"><code>String</code></a> object, with interface corresponding to <a href="IO.html"><code>IO</code></a>.</p>

<p>Commonly used to simulate <code>$stdio</code> or <code>$stderr</code></p>

<h3 id="class-StringIO-label-Examples">Examples<span><a href="#class-StringIO-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;stringio&#39;</span>

<span class="ruby-comment"># Writing stream emulation</span>
<span class="ruby-identifier">io</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">io</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Hello World&quot;</span>
<span class="ruby-identifier">io</span>.<span class="ruby-identifier">string</span> <span class="ruby-comment">#=&gt; &quot;Hello World\n&quot;</span>

<span class="ruby-comment"># Reading stream emulation</span>
<span class="ruby-identifier">io</span> = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span> <span class="ruby-string">&quot;first\nsecond\nlast\n&quot;</span>
<span class="ruby-identifier">io</span>.<span class="ruby-identifier">getc</span> <span class="ruby-comment">#=&gt; &quot;f&quot;</span>
<span class="ruby-identifier">io</span>.<span class="ruby-identifier">gets</span> <span class="ruby-comment">#=&gt; &quot;irst\n&quot;</span>
<span class="ruby-identifier">io</span>.<span class="ruby-identifier">read</span> <span class="ruby-comment">#=&gt; &quot;second\nlast\n&quot;</span>
</pre>

  </section>

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

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="VERSION">VERSION
        
        <dd>
        
      
      </dl>
    </section>
    

    

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

    
      <div id="method-c-new" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            new(string=&quot;&quot;[, mode])
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Creates new <a href="StringIO.html"><code>StringIO</code></a> instance from with <em>string</em> and <em>mode</em>.</p>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre>static VALUE
strio_initialize(int argc, VALUE *argv, VALUE self)
{
    struct StringIO *ptr = check_strio(self);

    if (!ptr) {
        DATA_PTR(self) = ptr = strio_alloc();
    }
    rb_call_super(0, 0);
    return strio_init(argc, argv, ptr, self);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-open" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            open(string=&quot;&quot;[, mode]) {|strio| ...}
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Equivalent to <a href="StringIO.html#method-c-new"><code>StringIO.new</code></a> except that when it is called with a block, it yields with the new instance and closes it, and returns the result which returned from the block.</p>
          
          

          
          <div class="method-source-code" id="open-source">
            <pre>static VALUE
strio_s_open(int argc, VALUE *argv, VALUE klass)
{
    VALUE obj = rb_class_new_instance_kw(argc, argv, klass, RB_PASS_CALLED_KEYWORDS);
    if (!rb_block_given_p()) return obj;
    return rb_ensure(rb_yield, obj, strio_finalize, obj);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

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

        <div class="method-description">
          
          <p>Puts stream into binary mode. See <a href="IO.html#method-i-binmode"><code>IO#binmode</code></a>.</p>
          
          

          
          <div class="method-source-code" id="binmode-source">
            <pre>static VALUE
strio_binmode(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    rb_encoding *enc = rb_ascii8bit_encoding();

    ptr-&gt;enc = enc;
    if (WRITABLE(self)) {
        rb_enc_associate(ptr-&gt;string, enc);
    }
    return self;
}</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="StringIO.html#method-i-each_byte"><code>each_byte</code></a>.</p>
          
          

          
          <div class="method-source-code" id="bytes-source">
            <pre>static VALUE
strio_bytes(VALUE self)
{
    rb_warn(&quot;StringIO#bytes is deprecated; use #each_byte instead&quot;);
    if (!rb_block_given_p())
        return rb_enumeratorize(self, ID2SYM(rb_intern(&quot;each_byte&quot;)), 0, 0);
    return strio_each_byte(self);
}</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="StringIO.html#method-i-each_char"><code>each_char</code></a>.</p>
          
          

          
          <div class="method-source-code" id="chars-source">
            <pre>static VALUE
strio_chars(VALUE self)
{
    rb_warn(&quot;StringIO#chars is deprecated; use #each_char instead&quot;);
    if (!rb_block_given_p())
        return rb_enumeratorize(self, ID2SYM(rb_intern(&quot;each_char&quot;)), 0, 0);
    return strio_each_char(self);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Closes a <a href="StringIO.html"><code>StringIO</code></a>. The stream is unavailable for any further data operations; an <code>IOError</code> is raised if such an attempt is made.</p>
          
          

          
          <div class="method-source-code" id="close-source">
            <pre>static VALUE
strio_close(VALUE self)
{
    StringIO(self);
    RBASIC(self)-&gt;flags &amp;= ~STRIO_READWRITE;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Closes the read end of a <a href="StringIO.html"><code>StringIO</code></a>.  Will raise an <code>IOError</code> if the receiver is not readable.</p>
          
          

          
          <div class="method-source-code" id="close_read-source">
            <pre>static VALUE
strio_close_read(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    if (!(ptr-&gt;flags &amp; FMODE_READABLE)) {
        rb_raise(rb_eIOError, &quot;closing non-duplex IO for reading&quot;);
    }
    RBASIC(self)-&gt;flags &amp;= ~STRIO_READABLE;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Closes the write end of a <a href="StringIO.html"><code>StringIO</code></a>.  Will raise an  <code>IOError</code> if the receiver is not writeable.</p>
          
          

          
          <div class="method-source-code" id="close_write-source">
            <pre>static VALUE
strio_close_write(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    if (!(ptr-&gt;flags &amp; FMODE_WRITABLE)) {
        rb_raise(rb_eIOError, &quot;closing non-duplex IO for writing&quot;);
    }
    RBASIC(self)-&gt;flags &amp;= ~STRIO_WRITABLE;
    return Qnil;
}</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 <code>true</code> if the stream is completely closed, <code>false</code> otherwise.</p>
          
          

          
          <div class="method-source-code" id="closed-3F-source">
            <pre>static VALUE
strio_closed(VALUE self)
{
    StringIO(self);
    if (!CLOSED(self)) return Qfalse;
    return Qtrue;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns <code>true</code> if the stream is not readable, <code>false</code> otherwise.</p>
          
          

          
          <div class="method-source-code" id="closed_read-3F-source">
            <pre>static VALUE
strio_closed_read(VALUE self)
{
    StringIO(self);
    if (READABLE(self)) return Qfalse;
    return Qtrue;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns <code>true</code> if the stream is not writable, <code>false</code> otherwise.</p>
          
          

          
          <div class="method-source-code" id="closed_write-3F-source">
            <pre>static VALUE
strio_closed_write(VALUE self)
{
    StringIO(self);
    if (WRITABLE(self)) return Qfalse;
    return Qtrue;
}</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="StringIO.html#method-i-each_codepoint"><code>each_codepoint</code></a>.</p>
          
          

          
          <div class="method-source-code" id="codepoints-source">
            <pre>static VALUE
strio_codepoints(VALUE self)
{
    rb_warn(&quot;StringIO#codepoints is deprecated; use #each_codepoint instead&quot;);
    if (!rb_block_given_p())
        return rb_enumeratorize(self, ID2SYM(rb_intern(&quot;each_codepoint&quot;)), 0, 0);
    return strio_each_codepoint(self);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-each"><code>IO#each</code></a>.</p>
          
          

          
          <div class="method-source-code" id="each-source">
            <pre>static VALUE
strio_each(int argc, VALUE *argv, VALUE self)
{
    VALUE line;
    struct getline_arg arg;

    StringIO(self);
    RETURN_ENUMERATOR(self, argc, argv);

    if (prepare_getline_args(&amp;arg, argc, argv)-&gt;limit == 0) {
        rb_raise(rb_eArgError, &quot;invalid limit: 0 for each_line&quot;);
    }

    while (!NIL_P(line = strio_getline(&amp;arg, readable(self)))) {
        rb_yield(line);
    }
    return self;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-each_byte"><code>IO#each_byte</code></a>.</p>
          
          

          
          <div class="method-source-code" id="each_byte-source">
            <pre>static VALUE
strio_each_byte(VALUE self)
{
    struct StringIO *ptr = readable(self);

    RETURN_ENUMERATOR(self, 0, 0);

    while (ptr-&gt;pos &lt; RSTRING_LEN(ptr-&gt;string)) {
        char c = RSTRING_PTR(ptr-&gt;string)[ptr-&gt;pos++];
        rb_yield(CHR2FIX(c));
    }
    return self;
}</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; strio
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_char                  &rarr; anEnumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-each_char"><code>IO#each_char</code></a>.</p>
          
          

          
          <div class="method-source-code" id="each_char-source">
            <pre>static VALUE
strio_each_char(VALUE self)
{
    VALUE c;

    RETURN_ENUMERATOR(self, 0, 0);

    while (!NIL_P(c = strio_getc(self))) {
        rb_yield(c);
    }
    return self;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-each_codepoint"><code>IO#each_codepoint</code></a>.</p>
          
          

          
          <div class="method-source-code" id="each_codepoint-source">
            <pre>static VALUE
strio_each_codepoint(VALUE self)
{
    struct StringIO *ptr;
    rb_encoding *enc;
    unsigned int c;
    int n;

    RETURN_ENUMERATOR(self, 0, 0);

    ptr = readable(self);
    enc = get_enc(ptr);
    for (;;) {
        if (ptr-&gt;pos &gt;= RSTRING_LEN(ptr-&gt;string)) {
            return self;
        }

        c = rb_enc_codepoint_len(RSTRING_PTR(ptr-&gt;string)+ptr-&gt;pos,
                                 RSTRING_END(ptr-&gt;string), &amp;n, enc);
        rb_yield(UINT2NUM(c));
        ptr-&gt;pos += n;
    }
    return self;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-each"><code>IO#each</code></a>.</p>
          
          

          
          <div class="method-source-code" id="each_line-source">
            <pre>static VALUE
strio_each(int argc, VALUE *argv, VALUE self)
{
    VALUE line;
    struct getline_arg arg;

    StringIO(self);
    RETURN_ENUMERATOR(self, argc, argv);

    if (prepare_getline_args(&amp;arg, argc, argv)-&gt;limit == 0) {
        rb_raise(rb_eArgError, &quot;invalid limit: 0 for each_line&quot;);
    }

    while (!NIL_P(line = strio_getline(&amp;arg, readable(self)))) {
        rb_yield(line);
    }
    return self;
}</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 stream is at the end of the data (underlying string). The stream must be opened for reading or an <code>IOError</code> will be raised.</p>
          
          

          
          <div class="method-source-code" id="eof-source">
            <pre>static VALUE
strio_eof(VALUE self)
{
    struct StringIO *ptr = readable(self);
    if (ptr-&gt;pos &lt; RSTRING_LEN(ptr-&gt;string)) return Qfalse;
    return Qtrue;
}</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 stream is at the end of the data (underlying string). The stream must be opened for reading or an <code>IOError</code> will be raised.</p>
          
          

          
          <div class="method-source-code" id="eof-3F-source">
            <pre>static VALUE
strio_eof(VALUE self)
{
    struct StringIO *ptr = readable(self);
    if (ptr-&gt;pos &lt; RSTRING_LEN(ptr-&gt;string)) return Qfalse;
    return Qtrue;
}</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 <a href="Encoding.html"><code>Encoding</code></a> object that represents the encoding of the file. If the stream is write mode and no encoding is specified, returns <code>nil</code>.</p>
          
          

          
          <div class="method-source-code" id="external_encoding-source">
            <pre>static VALUE
strio_external_encoding(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    return rb_enc_from_encoding(get_enc(ptr));
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a>.</p>
          
          

          
          <div class="method-source-code" id="fcntl-source">
            <pre>static VALUE
strio_unimpl(int argc, VALUE *argv, VALUE self)
{
    StringIO(self);
    rb_notimplement();

    UNREACHABLE;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns <code>nil</code>.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="fileno-source">
            <pre>static VALUE
strio_nil(VALUE self)
{
    StringIO(self);
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns an object itself.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="flush-source">
            <pre>static VALUE
strio_self(VALUE self)
{
    StringIO(self);
    return self;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns 0.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="fsync-source">
            <pre>static VALUE
strio_0(VALUE self)
{
    StringIO(self);
    return INT2FIX(0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-getbyte"><code>IO#getbyte</code></a>.</p>
          
          

          
          <div class="method-source-code" id="getbyte-source">
            <pre>static VALUE
strio_getbyte(VALUE self)
{
    struct StringIO *ptr = readable(self);
    int c;
    if (ptr-&gt;pos &gt;= RSTRING_LEN(ptr-&gt;string)) {
        return Qnil;
    }
    c = RSTRING_PTR(ptr-&gt;string)[ptr-&gt;pos++];
    return CHR2FIX(c);
}</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>See <a href="IO.html#method-i-getc"><code>IO#getc</code></a>.</p>
          
          

          
          <div class="method-source-code" id="getc-source">
            <pre>static VALUE
strio_getc(VALUE self)
{
    struct StringIO *ptr = readable(self);
    rb_encoding *enc = get_enc(ptr);
    VALUE str = ptr-&gt;string;
    long pos = ptr-&gt;pos;
    int len;
    char *p;

    if (pos &gt;= RSTRING_LEN(str)) {
        return Qnil;
    }
    p = RSTRING_PTR(str)+pos;
    len = rb_enc_mbclen(p, RSTRING_END(str), enc);
    ptr-&gt;pos += len;
    return enc_subseq(str, pos, len, enc);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-gets" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            gets(sep=$/, chomp: false)     &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, chomp: false)      &rarr; string or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gets(sep, limit, chomp: false) &rarr; string or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-gets"><code>IO#gets</code></a>.</p>
          
          

          
          <div class="method-source-code" id="gets-source">
            <pre>static VALUE
strio_gets(int argc, VALUE *argv, VALUE self)
{
    struct getline_arg arg;
    VALUE str;

    if (prepare_getline_args(&amp;arg, argc, argv)-&gt;limit == 0) {
        struct StringIO *ptr = readable(self);
        return rb_enc_str_new(0, 0, get_enc(ptr));
    }

    str = strio_getline(&amp;arg, readable(self));
    rb_lastline_set(str);
    return str;
}</pre>
          </div>
          
        </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 <a href="Encoding.html"><code>Encoding</code></a> of the internal string if conversion is specified.  Otherwise returns <code>nil</code>.</p>
          
          

          
          <div class="method-source-code" id="internal_encoding-source">
            <pre>static VALUE
strio_internal_encoding(VALUE self)
{
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns <code>false</code>.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="isatty-source">
            <pre>static VALUE
strio_false(VALUE self)
{
    StringIO(self);
    return Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the size of the buffer string.</p>
          
          

          
          <div class="method-source-code" id="length-source">
            <pre>static VALUE
strio_size(VALUE self)
{
    VALUE string = StringIO(self)-&gt;string;
    if (NIL_P(string)) {
        rb_raise(rb_eIOError, &quot;not opened&quot;);
    }
    return ULONG2NUM(RSTRING_LEN(string));
}</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. The stream must be opened for reading. <code>lineno</code> counts the number of times  <code>gets</code> is called, rather than the number of newlines  encountered. The two values will differ if <code>gets</code> is  called with a separator other than newline.  See also the  <code>$.</code> variable.</p>
          
          

          
          <div class="method-source-code" id="lineno-source">
            <pre>static VALUE
strio_get_lineno(VALUE self)
{
    return LONG2NUM(StringIO(self)-&gt;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>Manually sets the current line number to the given value. <code>$.</code> is updated only on the next read.</p>
          
          

          
          <div class="method-source-code" id="lineno-3D-source">
            <pre>static VALUE
strio_set_lineno(VALUE self, VALUE lineno)
{
    StringIO(self)-&gt;lineno = NUM2LONG(lineno);
    return lineno;
}</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="StringIO.html#method-i-each_line"><code>each_line</code></a>.</p>
          
          

          
          <div class="method-source-code" id="lines-source">
            <pre>static VALUE
strio_lines(int argc, VALUE *argv, VALUE self)
{
    rb_warn(&quot;StringIO#lines is deprecated; use #each_line instead&quot;);
    if (!rb_block_given_p())
        return rb_enumeratorize(self, ID2SYM(rb_intern(&quot;each_line&quot;)), argc, argv);
    return strio_each(argc, argv, self);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns <code>nil</code>.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="pid-source">
            <pre>static VALUE
strio_nil(VALUE self)
{
    StringIO(self);
    return Qnil;
}</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-heading">
          <span class="method-callseq">
            tell    &rarr; integer
          </span>
          
        </div>
        
        

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

          
          <div class="method-source-code" id="pos-source">
            <pre>static VALUE
strio_get_pos(VALUE self)
{
    return LONG2NUM(StringIO(self)-&gt;pos);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

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

          
          <div class="method-source-code" id="pos-3D-source">
            <pre>static VALUE
strio_set_pos(VALUE self, VALUE pos)
{
    struct StringIO *ptr = StringIO(self);
    long p = NUM2LONG(pos);
    if (p &lt; 0) {
        error_inval(0);
    }
    ptr-&gt;pos = p;
    return pos;
}</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>See <a href="IO.html#method-i-putc"><code>IO#putc</code></a>.</p>
          
          

          
          <div class="method-source-code" id="putc-source">
            <pre>static VALUE
strio_putc(VALUE self, VALUE ch)
{
    struct StringIO *ptr = writable(self);
    VALUE str;

    check_modifiable(ptr);
    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);
    }
    strio_write(self, str);
    return ch;
}</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>See <a href="IO.html#method-i-read"><code>IO#read</code></a>.</p>
          
          

          
          <div class="method-source-code" id="read-source">
            <pre>static VALUE
strio_read(int argc, VALUE *argv, VALUE self)
{
    struct StringIO *ptr = readable(self);
    VALUE str = Qnil;
    long len;
    int binary = 0;

    rb_check_arity(argc, 0, 2);
    switch (argc) {
      case 2:
        str = argv[1];
        if (!NIL_P(str)) {
            StringValue(str);
            rb_str_modify(str);
        }
        /* fall through */
      case 1:
        if (!NIL_P(argv[0])) {
            len = NUM2LONG(argv[0]);
            if (len &lt; 0) {
                rb_raise(rb_eArgError, &quot;negative length %ld given&quot;, len);
            }
            if (len &gt; 0 &amp;&amp; ptr-&gt;pos &gt;= RSTRING_LEN(ptr-&gt;string)) {
                if (!NIL_P(str)) rb_str_resize(str, 0);
                return Qnil;
            }
            binary = 1;
            break;
        }
        /* fall through */
      case 0:
        len = RSTRING_LEN(ptr-&gt;string);
        if (len &lt;= ptr-&gt;pos) {
            rb_encoding *enc = get_enc(ptr);
            if (NIL_P(str)) {
                str = rb_str_new(0, 0);
            }
            else {
                rb_str_resize(str, 0);
            }
            rb_enc_associate(str, enc);
            return str;
        }
        else {
            len -= ptr-&gt;pos;
        }
        break;
    }
    if (NIL_P(str)) {
        rb_encoding *enc = binary ? rb_ascii8bit_encoding() : get_enc(ptr);
        str = strio_substr(ptr, ptr-&gt;pos, len, enc);
    }
    else {
        long rest = RSTRING_LEN(ptr-&gt;string) - ptr-&gt;pos;
        if (len &gt; rest) len = rest;
        rb_str_resize(str, len);
        MEMCPY(RSTRING_PTR(str), RSTRING_PTR(ptr-&gt;string) + ptr-&gt;pos, char, len);
        if (binary)
            rb_enc_associate(str, rb_ascii8bit_encoding());
        else
            rb_enc_copy(str, ptr-&gt;string);
    }
    ptr-&gt;pos += RSTRING_LEN(str);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-readlines"><code>IO#readlines</code></a>.</p>
          
          

          
          <div class="method-source-code" id="readlines-source">
            <pre>static VALUE
strio_readlines(int argc, VALUE *argv, VALUE self)
{
    VALUE ary, line;
    struct getline_arg arg;

    StringIO(self);
    ary = rb_ary_new();
    if (prepare_getline_args(&amp;arg, argc, argv)-&gt;limit == 0) {
        rb_raise(rb_eArgError, &quot;invalid limit: 0 for readlines&quot;);
    }

    while (!NIL_P(line = strio_getline(&amp;arg, readable(self)))) {
        rb_ary_push(ary, line);
    }
    return ary;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-reopen" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            reopen(other_StrIO)     &rarr; strio
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            reopen(string, mode)    &rarr; strio
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Reinitializes the stream with the given <em>other_StrIO</em> or <em>string</em> and <em>mode</em> (see StringIO#new).</p>
          
          

          
          <div class="method-source-code" id="reopen-source">
            <pre>static VALUE
strio_reopen(int argc, VALUE *argv, VALUE self)
{
    rb_io_taint_check(self);
    if (argc == 1 &amp;&amp; !RB_TYPE_P(*argv, T_STRING)) {
        return strio_copy(self, *argv);
    }
    return strio_init(argc, argv, StringIO(self), self);
}</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 stream to the beginning of input, resetting <code>lineno</code> to zero.</p>
          
          

          
          <div class="method-source-code" id="rewind-source">
            <pre>static VALUE
strio_rewind(VALUE self)
{
    struct StringIO *ptr = StringIO(self);
    ptr-&gt;pos = 0;
    ptr-&gt;lineno = 0;
    return INT2FIX(0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Seeks to a given offset <em>amount</em> in the stream according to the value of <em>whence</em> (see <a href="IO.html#method-i-seek"><code>IO#seek</code></a>).</p>
          
          

          
          <div class="method-source-code" id="seek-source">
            <pre>static VALUE
strio_seek(int argc, VALUE *argv, VALUE self)
{
    VALUE whence;
    struct StringIO *ptr = StringIO(self);
    long amount, offset;

    rb_scan_args(argc, argv, &quot;11&quot;, NULL, &amp;whence);
    amount = NUM2LONG(argv[0]);
    if (CLOSED(self)) {
        rb_raise(rb_eIOError, &quot;closed stream&quot;);
    }
    switch (NIL_P(whence) ? 0 : NUM2LONG(whence)) {
      case 0:
        offset = 0;
        break;
      case 1:
        offset = ptr-&gt;pos;
        break;
      case 2:
        offset = RSTRING_LEN(ptr-&gt;string);
        break;
      default:
        error_inval(&quot;invalid whence&quot;);
    }
    if (amount &gt; LONG_MAX - offset || amount + offset &lt; 0) {
        error_inval(0);
    }
    ptr-&gt;pos = amount + offset;
    return INT2FIX(0);
}</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, [int_enc[, opt]])  &rarr; strio
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Specify the encoding of the <a href="StringIO.html"><code>StringIO</code></a> as <em>ext_enc</em>. Use the default external encoding if <em>ext_enc</em> is nil. 2nd argument <em>int_enc</em> and optional hash <em>opt</em> argument are ignored; they are for API compatibility to <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="set_encoding-source">
            <pre>static VALUE
strio_set_encoding(int argc, VALUE *argv, VALUE self)
{
    rb_encoding* enc;
    struct StringIO *ptr = StringIO(self);
    VALUE ext_enc, int_enc, opt;

    argc = rb_scan_args(argc, argv, &quot;11:&quot;, &amp;ext_enc, &amp;int_enc, &amp;opt);

    if (NIL_P(ext_enc)) {
        enc = rb_default_external_encoding();
    }
    else {
        enc = rb_to_encoding(ext_enc);
    }
    ptr-&gt;enc = enc;
    if (WRITABLE(self)) {
        rb_enc_associate(ptr-&gt;string, enc);
    }

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

        

        
      </div>

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

        <div class="method-description">
          
          
          
          

          
          <div class="method-source-code" id="set_encoding_by_bom-source">
            <pre>static VALUE
strio_set_encoding_by_bom(VALUE self)
{
    struct StringIO *ptr = StringIO(self);

    if (!set_encoding_by_bom(ptr)) return Qnil;
    return rb_enc_from_encoding(ptr-&gt;enc);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the size of the buffer string.</p>
          
          

          
          <div class="method-source-code" id="size-source">
            <pre>static VALUE
strio_size(VALUE self)
{
    VALUE string = StringIO(self)-&gt;string;
    if (NIL_P(string)) {
        rb_raise(rb_eIOError, &quot;not opened&quot;);
    }
    return ULONG2NUM(RSTRING_LEN(string));
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns underlying <a href="String.html"><code>String</code></a> object, the subject of <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="string-source">
            <pre>static VALUE
strio_get_string(VALUE self)
{
    return StringIO(self)-&gt;string;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Changes underlying <a href="String.html"><code>String</code></a> object, the subject of <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="string-3D-source">
            <pre>static VALUE
strio_set_string(VALUE self, VALUE string)
{
    struct StringIO *ptr = StringIO(self);

    rb_io_taint_check(self);
    ptr-&gt;flags &amp;= ~FMODE_READWRITE;
    StringValue(string);
    ptr-&gt;flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
    ptr-&gt;pos = 0;
    ptr-&gt;lineno = 0;
    return ptr-&gt;string = string;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns <code>true</code> always.</p>
          
          

          
          <div class="method-source-code" id="sync-source">
            <pre>static VALUE
strio_get_sync(VALUE self)
{
    StringIO(self);
    return Qtrue;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the argument unchanged.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="sync-3D-source">
            <pre>static VALUE
strio_first(VALUE self, VALUE arg)
{
    StringIO(self);
    return arg;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-tell" 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-heading">
          <span class="method-callseq">
            tell    &rarr; integer
          </span>
          
        </div>
        
        

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

          
          <div class="method-source-code" id="tell-source">
            <pre>static VALUE
strio_get_pos(VALUE self)
{
    return LONG2NUM(StringIO(self)-&gt;pos);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Truncates the buffer string to at most <em>integer</em> bytes. The stream must be opened for writing.</p>
          
          

          
          <div class="method-source-code" id="truncate-source">
            <pre>static VALUE
strio_truncate(VALUE self, VALUE len)
{
    VALUE string = writable(self)-&gt;string;
    long l = NUM2LONG(len);
    long plen = RSTRING_LEN(string);
    if (l &lt; 0) {
        error_inval(&quot;negative length&quot;);
    }
    rb_str_resize(string, l);
    if (plen &lt; l) {
        MEMZERO(RSTRING_PTR(string) + plen, char, l - plen);
    }
    return len;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns <code>false</code>.  Just for compatibility to <a href="IO.html"><code>IO</code></a>.</p>
          
          

          
          <div class="method-source-code" id="tty-3F-source">
            <pre>static VALUE
strio_false(VALUE self)
{
    StringIO(self);
    return Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>See <a href="IO.html#method-i-ungetbyte"><code>IO#ungetbyte</code></a></p>
          
          

          
          <div class="method-source-code" id="ungetbyte-source">
            <pre>static VALUE
strio_ungetbyte(VALUE self, VALUE c)
{
    struct StringIO *ptr = readable(self);

    check_modifiable(ptr);
    if (NIL_P(c)) return Qnil;
    if (RB_INTEGER_TYPE_P(c)) {
        /* rb_int_and() not visible from exts */
        VALUE v = rb_funcall(c, &#39;&amp;&#39;, 1, INT2FIX(0xff));
        const char cc = NUM2INT(v) &amp; 0xFF;
        strio_unget_bytes(ptr, &amp;cc, 1);
    }
    else {
        long cl;
        SafeStringValue(c);
        cl = RSTRING_LEN(c);
        if (cl &gt; 0) {
            strio_unget_bytes(ptr, RSTRING_PTR(c), cl);
            RB_GC_GUARD(c);
        }
    }
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Pushes back one character (passed as a parameter) such that a subsequent buffered read will return it.  There is no limitation for multiple pushbacks including pushing back behind the beginning of the buffer string.</p>
          
          

          
          <div class="method-source-code" id="ungetc-source">
            <pre>static VALUE
strio_ungetc(VALUE self, VALUE c)
{
    struct StringIO *ptr = readable(self);
    rb_encoding *enc, *enc2;

    check_modifiable(ptr);
    if (NIL_P(c)) return Qnil;
    if (RB_INTEGER_TYPE_P(c)) {
        int len, cc = NUM2INT(c);
        char buf[16];

        enc = rb_enc_get(ptr-&gt;string);
        len = rb_enc_codelen(cc, enc);
        if (len &lt;= 0) rb_enc_uint_chr(cc, enc);
        rb_enc_mbcput(cc, buf, enc);
        return strio_unget_bytes(ptr, buf, len);
    }
    else {
        SafeStringValue(c);
        enc = rb_enc_get(ptr-&gt;string);
        enc2 = rb_enc_get(c);
        if (enc != enc2 &amp;&amp; enc != rb_ascii8bit_encoding()) {
            c = rb_str_conv_enc(c, enc2, enc);
        }
        strio_unget_bytes(ptr, RSTRING_PTR(c), RSTRING_LEN(c));
        RB_GC_GUARD(c);
        return Qnil;
    }
}</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-heading">
          <span class="method-callseq">
            syswrite(string)   &rarr; integer
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Appends the given string to the underlying buffer string. The stream must be opened for writing.  If the argument is not a string, it will be converted to a string using <code>to_s</code>. Returns the number of bytes written.  See <a href="IO.html#method-i-write"><code>IO#write</code></a>.</p>
          
          

          
          <div class="method-source-code" id="write-source">
            <pre>static VALUE
strio_write_m(int argc, VALUE *argv, VALUE self)
{
    long len = 0;
    while (argc-- &gt; 0) {
        /* StringIO can&#39;t exceed long limit */
        len += strio_write(self, *argv++);
    }
    return LONG2NUM(len);
}</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>