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

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

<title>class String - 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="Comparable.html">Comparable</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-try_convert">::try_convert</a>
    
    <li ><a href="#method-i-25">#%</a>
    
    <li ><a href="#method-i-2A">#*</a>
    
    <li ><a href="#method-i-2B">#+</a>
    
    <li ><a href="#method-i-2B-40">#+@</a>
    
    <li ><a href="#method-i-2D-40">#-@</a>
    
    <li ><a href="#method-i-3C-3C">#&lt;&lt;</a>
    
    <li ><a href="#method-i-3C-3D-3E">#&lt;=&gt;</a>
    
    <li ><a href="#method-i-3D-3D">#==</a>
    
    <li ><a href="#method-i-3D-3D-3D">#===</a>
    
    <li ><a href="#method-i-3D~">#=~</a>
    
    <li ><a href="#method-i-5B-5D">#[]</a>
    
    <li ><a href="#method-i-5B-5D-3D">#[]=</a>
    
    <li ><a href="#method-i-ascii_only-3F">#ascii_only?</a>
    
    <li ><a href="#method-i-b">#b</a>
    
    <li ><a href="#method-i-bytes">#bytes</a>
    
    <li ><a href="#method-i-bytesize">#bytesize</a>
    
    <li ><a href="#method-i-byteslice">#byteslice</a>
    
    <li ><a href="#method-i-capitalize">#capitalize</a>
    
    <li ><a href="#method-i-capitalize-21">#capitalize!</a>
    
    <li ><a href="#method-i-casecmp">#casecmp</a>
    
    <li ><a href="#method-i-casecmp-3F">#casecmp?</a>
    
    <li ><a href="#method-i-center">#center</a>
    
    <li ><a href="#method-i-chars">#chars</a>
    
    <li ><a href="#method-i-chomp">#chomp</a>
    
    <li ><a href="#method-i-chomp-21">#chomp!</a>
    
    <li ><a href="#method-i-chop">#chop</a>
    
    <li ><a href="#method-i-chop-21">#chop!</a>
    
    <li ><a href="#method-i-chr">#chr</a>
    
    <li ><a href="#method-i-clear">#clear</a>
    
    <li ><a href="#method-i-codepoints">#codepoints</a>
    
    <li ><a href="#method-i-concat">#concat</a>
    
    <li ><a href="#method-i-count">#count</a>
    
    <li ><a href="#method-i-crypt">#crypt</a>
    
    <li ><a href="#method-i-delete">#delete</a>
    
    <li ><a href="#method-i-delete-21">#delete!</a>
    
    <li ><a href="#method-i-delete_prefix">#delete_prefix</a>
    
    <li ><a href="#method-i-delete_prefix-21">#delete_prefix!</a>
    
    <li ><a href="#method-i-delete_suffix">#delete_suffix</a>
    
    <li ><a href="#method-i-delete_suffix-21">#delete_suffix!</a>
    
    <li ><a href="#method-i-downcase">#downcase</a>
    
    <li ><a href="#method-i-downcase-21">#downcase!</a>
    
    <li ><a href="#method-i-dump">#dump</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_grapheme_cluster">#each_grapheme_cluster</a>
    
    <li ><a href="#method-i-each_line">#each_line</a>
    
    <li ><a href="#method-i-empty-3F">#empty?</a>
    
    <li ><a href="#method-i-encode">#encode</a>
    
    <li ><a href="#method-i-encode-21">#encode!</a>
    
    <li ><a href="#method-i-encoding">#encoding</a>
    
    <li ><a href="#method-i-end_with-3F">#end_with?</a>
    
    <li ><a href="#method-i-eql-3F">#eql?</a>
    
    <li ><a href="#method-i-force_encoding">#force_encoding</a>
    
    <li ><a href="#method-i-freeze">#freeze</a>
    
    <li ><a href="#method-i-getbyte">#getbyte</a>
    
    <li ><a href="#method-i-grapheme_clusters">#grapheme_clusters</a>
    
    <li ><a href="#method-i-gsub">#gsub</a>
    
    <li ><a href="#method-i-gsub-21">#gsub!</a>
    
    <li ><a href="#method-i-hash">#hash</a>
    
    <li ><a href="#method-i-hex">#hex</a>
    
    <li ><a href="#method-i-include-3F">#include?</a>
    
    <li ><a href="#method-i-index">#index</a>
    
    <li ><a href="#method-i-initialize_copy">#initialize_copy</a>
    
    <li ><a href="#method-i-insert">#insert</a>
    
    <li ><a href="#method-i-inspect">#inspect</a>
    
    <li ><a href="#method-i-intern">#intern</a>
    
    <li ><a href="#method-i-iseuc">#iseuc</a>
    
    <li ><a href="#method-i-isjis">#isjis</a>
    
    <li ><a href="#method-i-issjis">#issjis</a>
    
    <li ><a href="#method-i-isutf8">#isutf8</a>
    
    <li ><a href="#method-i-kconv">#kconv</a>
    
    <li ><a href="#method-i-length">#length</a>
    
    <li ><a href="#method-i-lines">#lines</a>
    
    <li ><a href="#method-i-ljust">#ljust</a>
    
    <li ><a href="#method-i-lstrip">#lstrip</a>
    
    <li ><a href="#method-i-lstrip-21">#lstrip!</a>
    
    <li ><a href="#method-i-match">#match</a>
    
    <li ><a href="#method-i-match-3F">#match?</a>
    
    <li ><a href="#method-i-next">#next</a>
    
    <li ><a href="#method-i-next-21">#next!</a>
    
    <li ><a href="#method-i-oct">#oct</a>
    
    <li ><a href="#method-i-ord">#ord</a>
    
    <li ><a href="#method-i-partition">#partition</a>
    
    <li ><a href="#method-i-prepend">#prepend</a>
    
    <li ><a href="#method-i-replace">#replace</a>
    
    <li ><a href="#method-i-reverse">#reverse</a>
    
    <li ><a href="#method-i-reverse-21">#reverse!</a>
    
    <li ><a href="#method-i-rindex">#rindex</a>
    
    <li ><a href="#method-i-rjust">#rjust</a>
    
    <li ><a href="#method-i-rpartition">#rpartition</a>
    
    <li ><a href="#method-i-rstrip">#rstrip</a>
    
    <li ><a href="#method-i-rstrip-21">#rstrip!</a>
    
    <li ><a href="#method-i-scan">#scan</a>
    
    <li ><a href="#method-i-scrub">#scrub</a>
    
    <li ><a href="#method-i-scrub-21">#scrub!</a>
    
    <li ><a href="#method-i-setbyte">#setbyte</a>
    
    <li ><a href="#method-i-shellescape">#shellescape</a>
    
    <li ><a href="#method-i-shellsplit">#shellsplit</a>
    
    <li ><a href="#method-i-size">#size</a>
    
    <li ><a href="#method-i-slice">#slice</a>
    
    <li ><a href="#method-i-slice-21">#slice!</a>
    
    <li ><a href="#method-i-split">#split</a>
    
    <li ><a href="#method-i-squeeze">#squeeze</a>
    
    <li ><a href="#method-i-squeeze-21">#squeeze!</a>
    
    <li ><a href="#method-i-start_with-3F">#start_with?</a>
    
    <li ><a href="#method-i-strip">#strip</a>
    
    <li ><a href="#method-i-strip-21">#strip!</a>
    
    <li ><a href="#method-i-sub">#sub</a>
    
    <li ><a href="#method-i-sub-21">#sub!</a>
    
    <li ><a href="#method-i-succ">#succ</a>
    
    <li ><a href="#method-i-succ-21">#succ!</a>
    
    <li ><a href="#method-i-sum">#sum</a>
    
    <li ><a href="#method-i-swapcase">#swapcase</a>
    
    <li ><a href="#method-i-swapcase-21">#swapcase!</a>
    
    <li ><a href="#method-i-to_c">#to_c</a>
    
    <li ><a href="#method-i-to_d">#to_d</a>
    
    <li ><a href="#method-i-to_f">#to_f</a>
    
    <li ><a href="#method-i-to_i">#to_i</a>
    
    <li ><a href="#method-i-to_r">#to_r</a>
    
    <li ><a href="#method-i-to_s">#to_s</a>
    
    <li ><a href="#method-i-to_str">#to_str</a>
    
    <li ><a href="#method-i-to_sym">#to_sym</a>
    
    <li ><a href="#method-i-toeuc">#toeuc</a>
    
    <li ><a href="#method-i-tojis">#tojis</a>
    
    <li ><a href="#method-i-tolocale">#tolocale</a>
    
    <li ><a href="#method-i-tosjis">#tosjis</a>
    
    <li ><a href="#method-i-toutf16">#toutf16</a>
    
    <li ><a href="#method-i-toutf32">#toutf32</a>
    
    <li ><a href="#method-i-toutf8">#toutf8</a>
    
    <li ><a href="#method-i-tr">#tr</a>
    
    <li ><a href="#method-i-tr-21">#tr!</a>
    
    <li ><a href="#method-i-tr_s">#tr_s</a>
    
    <li ><a href="#method-i-tr_s-21">#tr_s!</a>
    
    <li ><a href="#method-i-undump">#undump</a>
    
    <li ><a href="#method-i-unicode_normalize">#unicode_normalize</a>
    
    <li ><a href="#method-i-unicode_normalize-21">#unicode_normalize!</a>
    
    <li ><a href="#method-i-unicode_normalized-3F">#unicode_normalized?</a>
    
    <li ><a href="#method-i-unpack">#unpack</a>
    
    <li ><a href="#method-i-unpack1">#unpack1</a>
    
    <li ><a href="#method-i-upcase">#upcase</a>
    
    <li ><a href="#method-i-upcase-21">#upcase!</a>
    
    <li ><a href="#method-i-upto">#upto</a>
    
    <li ><a href="#method-i-valid_encoding-3F">#valid_encoding?</a>
    
  </ul>
</div>

  </div>
</nav>

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

  <section class="description">
    
<p>A <a href="String.html"><code>String</code></a> object holds and manipulates an arbitrary sequence of bytes, typically representing characters. <a href="String.html"><code>String</code></a> objects may be created using <a href="String.html#method-c-new"><code>String::new</code></a> or as literals.</p>

<p>Because of aliasing issues, users of strings should be aware of the methods that modify the contents of a <a href="String.html"><code>String</code></a> object.  Typically, methods with names ending in “!&#39;&#39; modify their receiver, while those without a “!&#39;&#39; return a new <a href="String.html"><code>String</code></a>.  However, there are exceptions, such as <a href="String.html#method-i-5B-5D-3D"><code>String#[]=</code></a>.</p>

  </section>

  
  <section id="5Buntitled-5D" class="documentation-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(str=&quot;&quot;)                   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            new(str=&quot;&quot;, encoding: enc)    &rarr; new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            new(str=&quot;&quot;, capacity: size)   &rarr; new_str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns a new string object containing a copy of <em>str</em>.</p>

<p>The optional <em>encoding</em> keyword argument specifies the encoding of the new string. If not specified, the encoding of <em>str</em> is used (or ASCII-8BIT, if <em>str</em> is not specified).</p>

<p>The optional <em>capacity</em> keyword argument specifies the size of the internal buffer. This may improve performance, when the string will be concatenated many times (causing many realloc calls).</p>
          
          

          
          <div class="method-source-code" id="new-source">
            <pre>static VALUE
rb_str_init(int argc, VALUE *argv, VALUE str)
{
    static ID keyword_ids[2];
    VALUE orig, opt, venc, vcapa;
    VALUE kwargs[2];
    rb_encoding *enc = 0;
    int n;

    if (!keyword_ids[0]) {
        keyword_ids[0] = rb_id_encoding();
        CONST_ID(keyword_ids[1], &quot;capacity&quot;);
    }

    n = rb_scan_args(argc, argv, &quot;01:&quot;, &amp;orig, &amp;opt);
    if (!NIL_P(opt)) {
        rb_get_kwargs(opt, keyword_ids, 0, 2, kwargs);
        venc = kwargs[0];
        vcapa = kwargs[1];
        if (venc != Qundef &amp;&amp; !NIL_P(venc)) {
            enc = rb_to_encoding(venc);
        }
        if (vcapa != Qundef &amp;&amp; !NIL_P(vcapa)) {
            long capa = NUM2LONG(vcapa);
            long len = 0;
            int termlen = enc ? rb_enc_mbminlen(enc) : 1;

            if (capa &lt; STR_BUF_MIN_SIZE) {
                capa = STR_BUF_MIN_SIZE;
            }
            if (n == 1) {
                StringValue(orig);
                len = RSTRING_LEN(orig);
                if (capa &lt; len) {
                    capa = len;
                }
                if (orig == str) n = 0;
            }
            str_modifiable(str);
            if (STR_EMBED_P(str)) { /* make noembed always */
                char *new_ptr = ALLOC_N(char, (size_t)capa + termlen);
                memcpy(new_ptr, RSTRING(str)-&gt;as.ary, RSTRING_EMBED_LEN_MAX + 1);
                RSTRING(str)-&gt;as.heap.ptr = new_ptr;
            }
            else if (FL_TEST(str, STR_SHARED|STR_NOFREE)) {
                const size_t size = (size_t)capa + termlen;
                const char *const old_ptr = RSTRING_PTR(str);
                const size_t osize = RSTRING(str)-&gt;as.heap.len + TERM_LEN(str);
                char *new_ptr = ALLOC_N(char, (size_t)capa + termlen);
                memcpy(new_ptr, old_ptr, osize &lt; size ? osize : size);
                FL_UNSET_RAW(str, STR_SHARED|STR_NOFREE);
                RSTRING(str)-&gt;as.heap.ptr = new_ptr;
            }
            else if (STR_HEAP_SIZE(str) != (size_t)capa + termlen) {
                SIZED_REALLOC_N(RSTRING(str)-&gt;as.heap.ptr, char,
                        (size_t)capa + termlen, STR_HEAP_SIZE(str));
            }
            RSTRING(str)-&gt;as.heap.len = len;
            TERM_FILL(&amp;RSTRING(str)-&gt;as.heap.ptr[len], termlen);
            if (n == 1) {
                memcpy(RSTRING(str)-&gt;as.heap.ptr, RSTRING_PTR(orig), len);
                rb_enc_cr_str_exact_copy(str, orig);
            }
            FL_SET(str, STR_NOEMBED);
            RSTRING(str)-&gt;as.heap.aux.capa = capa;
        }
        else if (n == 1) {
            rb_str_replace(str, orig);
        }
        if (enc) {
            rb_enc_associate(str, enc);
            ENC_CODERANGE_CLEAR(str);
        }
    }
    else if (n == 1) {
        rb_str_replace(str, orig);
    }
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Try to convert <em>obj</em> into a <a href="String.html"><code>String</code></a>, using <a href="String.html#method-i-to_str"><code>to_str</code></a> method. Returns converted string or nil if <em>obj</em> cannot be converted for any reason.</p>

<pre class="ruby"><span class="ruby-constant">String</span>.<span class="ruby-identifier">try_convert</span>(<span class="ruby-string">&quot;str&quot;</span>)     <span class="ruby-comment">#=&gt; &quot;str&quot;</span>
<span class="ruby-constant">String</span>.<span class="ruby-identifier">try_convert</span>(<span class="ruby-regexp">/re/</span>)      <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="try_convert-source">
            <pre>static VALUE
rb_str_s_try_convert(VALUE dummy, VALUE str)
{
    return rb_check_string_type(str);
}</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-25" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            str % arg   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Format—Uses <em>str</em> as a format specification, and returns the result of applying it to <em>arg</em>. If the format specification contains more than one substitution, then <em>arg</em> must be an <a href="Array.html"><code>Array</code></a> or <a href="Hash.html"><code>Hash</code></a> containing the values to be substituted. See <a href="Kernel.html#method-i-sprintf"><code>Kernel#sprintf</code></a> for details of the format string.</p>

<pre class="ruby"><span class="ruby-string">&quot;%05d&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-value">123</span>                              <span class="ruby-comment">#=&gt; &quot;00123&quot;</span>
<span class="ruby-string">&quot;%-5s: %016x&quot;</span> <span class="ruby-operator">%</span> [ <span class="ruby-string">&quot;ID&quot;</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">object_id</span> ]  <span class="ruby-comment">#=&gt; &quot;ID   : 00002b054ec93168&quot;</span>
<span class="ruby-string">&quot;foo = %{foo}&quot;</span> <span class="ruby-operator">%</span> { <span class="ruby-value">:foo</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;bar&#39;</span> }        <span class="ruby-comment">#=&gt; &quot;foo = bar&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="25-source">
            <pre>static VALUE
rb_str_format_m(VALUE str, VALUE arg)
{
    VALUE tmp = rb_check_array_type(arg);

    if (!NIL_P(tmp)) {
        return rb_str_format(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp), str);
    }
    return rb_str_format(1, &amp;arg, str);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Copy — Returns a new <a href="String.html"><code>String</code></a> containing <code>integer</code> copies of the receiver. <code>integer</code> must be greater than or equal to 0.</p>

<pre class="ruby"><span class="ruby-string">&quot;Ho! &quot;</span> <span class="ruby-operator">*</span> <span class="ruby-value">3</span>   <span class="ruby-comment">#=&gt; &quot;Ho! Ho! Ho! &quot;</span>
<span class="ruby-string">&quot;Ho! &quot;</span> <span class="ruby-operator">*</span> <span class="ruby-value">0</span>   <span class="ruby-comment">#=&gt; &quot;&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="2A-source">
            <pre>VALUE
rb_str_times(VALUE str, VALUE times)
{
    VALUE str2;
    long n, len;
    char *ptr2;
    int termlen;

    if (times == INT2FIX(1)) {
        return rb_str_dup(str);
    }
    if (times == INT2FIX(0)) {
        str2 = str_alloc(rb_obj_class(str));
        rb_enc_copy(str2, str);
        return str2;
    }
    len = NUM2LONG(times);
    if (len &lt; 0) {
        rb_raise(rb_eArgError, &quot;negative argument&quot;);
    }
    if (RSTRING_LEN(str) == 1 &amp;&amp; RSTRING_PTR(str)[0] == 0) {
       str2 = str_alloc(rb_obj_class(str));
       if (!STR_EMBEDDABLE_P(len, 1)) {
           RSTRING(str2)-&gt;as.heap.aux.capa = len;
           RSTRING(str2)-&gt;as.heap.ptr = ZALLOC_N(char, (size_t)len + 1);
           STR_SET_NOEMBED(str2);
       }
       STR_SET_LEN(str2, len);
       rb_enc_copy(str2, str);
       return str2;
    }
    if (len &amp;&amp; LONG_MAX/len &lt;  RSTRING_LEN(str)) {
        rb_raise(rb_eArgError, &quot;argument too big&quot;);
    }

    len *= RSTRING_LEN(str);
    termlen = TERM_LEN(str);
    str2 = str_new0(rb_obj_class(str), 0, len, termlen);
    ptr2 = RSTRING_PTR(str2);
    if (len) {
        n = RSTRING_LEN(str);
        memcpy(ptr2, RSTRING_PTR(str), n);
        while (n &lt;= len/2) {
            memcpy(ptr2 + n, ptr2, n);
            n *= 2;
        }
        memcpy(ptr2 + n, ptr2, len-n);
    }
    STR_SET_LEN(str2, len);
    TERM_FILL(&amp;ptr2[len], termlen);
    rb_enc_cr_str_copy_for_substr(str2, str);

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

        

        
      </div>

    
      <div id="method-i-2B" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            str + other_str   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Concatenation—Returns a new <a href="String.html"><code>String</code></a> containing <em>other_str</em> concatenated to <em>str</em>.</p>

<pre class="ruby"><span class="ruby-string">&quot;Hello from &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">to_s</span>   <span class="ruby-comment">#=&gt; &quot;Hello from main&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="2B-source">
            <pre>VALUE
rb_str_plus(VALUE str1, VALUE str2)
{
    VALUE str3;
    rb_encoding *enc;
    char *ptr1, *ptr2, *ptr3;
    long len1, len2;
    int termlen;

    StringValue(str2);
    enc = rb_enc_check_str(str1, str2);
    RSTRING_GETMEM(str1, ptr1, len1);
    RSTRING_GETMEM(str2, ptr2, len2);
    termlen = rb_enc_mbminlen(enc);
    if (len1 &gt; LONG_MAX - len2) {
        rb_raise(rb_eArgError, &quot;string size too big&quot;);
    }
    str3 = str_new0(rb_cString, 0, len1+len2, termlen);
    ptr3 = RSTRING_PTR(str3);
    memcpy(ptr3, ptr1, len1);
    memcpy(ptr3+len1, ptr2, len2);
    TERM_FILL(&amp;ptr3[len1+len2], termlen);

    ENCODING_CODERANGE_SET(str3, rb_enc_to_index(enc),
                           ENC_CODERANGE_AND(ENC_CODERANGE(str1), ENC_CODERANGE(str2)));
    RB_GC_GUARD(str1);
    RB_GC_GUARD(str2);
    return str3;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-2B-40" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            +str  &rarr; str (mutable)
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>If the string is frozen, then return duplicated mutable string.</p>

<p>If the string is not frozen, then return the string itself.</p>
          
          

          
          <div class="method-source-code" id="2B-40-source">
            <pre>static VALUE
str_uplus(VALUE str)
{
    if (OBJ_FROZEN(str)) {
        return rb_str_dup(str);
    }
    else {
        return str;
    }
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-2D-40" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            -str  &rarr; str (frozen)
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns a frozen, possibly pre-existing copy of the string.</p>

<p>The string will be deduplicated as long as it does not have any instance variables set on it.</p>
          
          

          
          <div class="method-source-code" id="2D-40-source">
            <pre>static VALUE
str_uminus(VALUE str)
{
    if (!BARE_STRING_P(str) &amp;&amp; !rb_obj_frozen_p(str)) {
        str = rb_str_dup(str);
    }
    return rb_fstring(str);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Appends the given object to <em>str</em>. If the object is an <a href="Integer.html"><code>Integer</code></a>, it is considered a codepoint and converted to a character before being appended.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;hello &quot;</span>
<span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-string">&quot;world&quot;</span>   <span class="ruby-comment">#=&gt; &quot;hello world&quot;</span>
<span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">33</span>        <span class="ruby-comment">#=&gt; &quot;hello world!&quot;</span>
</pre>

<p>See also <a href="String.html#method-i-concat"><code>String#concat</code></a>, which takes multiple arguments.</p>
          
          

          
          <div class="method-source-code" id="3C-3C-source">
            <pre>VALUE
rb_str_concat(VALUE str1, VALUE str2)
{
    unsigned int code;
    rb_encoding *enc = STR_ENC_GET(str1);
    int encidx;

    if (RB_INTEGER_TYPE_P(str2)) {
        if (rb_num_to_uint(str2, &amp;code) == 0) {
        }
        else if (FIXNUM_P(str2)) {
            rb_raise(rb_eRangeError, &quot;%ld out of char range&quot;, FIX2LONG(str2));
        }
        else {
            rb_raise(rb_eRangeError, &quot;bignum out of char range&quot;);
        }
    }
    else {
        return rb_str_append(str1, str2);
    }

    encidx = rb_enc_to_index(enc);
    if (encidx == ENCINDEX_ASCII || encidx == ENCINDEX_US_ASCII) {
        /* US-ASCII automatically extended to ASCII-8BIT */
        char buf[1];
        buf[0] = (char)code;
        if (code &gt; 0xFF) {
            rb_raise(rb_eRangeError, &quot;%u out of char range&quot;, code);
        }
        rb_str_cat(str1, buf, 1);
        if (encidx == ENCINDEX_US_ASCII &amp;&amp; code &gt; 127) {
            rb_enc_associate_index(str1, ENCINDEX_ASCII);
            ENC_CODERANGE_SET(str1, ENC_CODERANGE_VALID);
        }
    }
    else {
        long pos = RSTRING_LEN(str1);
        int cr = ENC_CODERANGE(str1);
        int len;
        char *buf;

        switch (len = rb_enc_codelen(code, enc)) {
          case ONIGERR_INVALID_CODE_POINT_VALUE:
            rb_raise(rb_eRangeError, &quot;invalid codepoint 0x%X in %s&quot;, code, rb_enc_name(enc));
            break;
          case ONIGERR_TOO_BIG_WIDE_CHAR_VALUE:
          case 0:
            rb_raise(rb_eRangeError, &quot;%u out of char range&quot;, code);
            break;
        }
        buf = ALLOCA_N(char, len + 1);
        rb_enc_mbcput(code, buf, enc);
        if (rb_enc_precise_mbclen(buf, buf + len + 1, enc) != len) {
            rb_raise(rb_eRangeError, &quot;invalid codepoint 0x%X in %s&quot;, code, rb_enc_name(enc));
        }
        rb_str_resize(str1, pos+len);
        memcpy(RSTRING_PTR(str1) + pos, buf, len);
        if (cr == ENC_CODERANGE_7BIT &amp;&amp; code &gt; 127)
            cr = ENC_CODERANGE_VALID;
        ENC_CODERANGE_SET(str1, cr);
    }
    return str1;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-3C-3D-3E" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            string &lt;=&gt; other_string   &rarr; -1, 0, +1, or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Comparison—Returns -1, 0, +1, or <code>nil</code> depending on whether <code>string</code> is less than, equal to, or greater than <code>other_string</code>.</p>

<p><code>nil</code> is returned if the two values are incomparable.</p>

<p>If the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered greater than the shorter one.</p>

<p><code>&lt;=&gt;</code> is the basis for the methods <code>&lt;</code>, <code>&lt;=</code>, <code>&gt;</code>, <code>&gt;=</code>, and <code>between?</code>, included from module <a href="Comparable.html"><code>Comparable</code></a>. The method String#== does not use Comparable#==.</p>

<pre class="ruby"><span class="ruby-string">&quot;abcdef&quot;</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-string">&quot;abcde&quot;</span>     <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-string">&quot;abcdef&quot;</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-string">&quot;abcdef&quot;</span>    <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-string">&quot;abcdef&quot;</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-string">&quot;abcdefg&quot;</span>   <span class="ruby-comment">#=&gt; -1</span>
<span class="ruby-string">&quot;abcdef&quot;</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-string">&quot;ABCDEF&quot;</span>    <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-string">&quot;abcdef&quot;</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-value">1</span>           <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="3C-3D-3E-source">
            <pre>static VALUE
rb_str_cmp_m(VALUE str1, VALUE str2)
{
    int result;
    VALUE s = rb_check_string_type(str2);
    if (NIL_P(s)) {
        return rb_invcmp(str1, str2);
    }
    result = rb_str_cmp(str1, s);
    return INT2FIX(result);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Equality—Returns whether <code>str</code> == <code>obj</code>, similar to Object#==.</p>

<p>If <code>obj</code> is not an instance of <a href="String.html"><code>String</code></a> but responds to <code>to_str</code>, then the two strings are compared using <code>obj.==</code>.</p>

<p>Otherwise, returns similarly to <a href="String.html#method-i-eql-3F"><code>String#eql?</code></a>, comparing length and content.</p>
          
          

          
          <div class="method-source-code" id="3D-3D-source">
            <pre>VALUE
rb_str_equal(VALUE str1, VALUE str2)
{
    if (str1 == str2) return Qtrue;
    if (!RB_TYPE_P(str2, T_STRING)) {
        if (!rb_respond_to(str2, idTo_str)) {
            return Qfalse;
        }
        return rb_equal(str2, str1);
    }
    return rb_str_eql_internal(str1, str2);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Equality—Returns whether <code>str</code> == <code>obj</code>, similar to Object#==.</p>

<p>If <code>obj</code> is not an instance of <a href="String.html"><code>String</code></a> but responds to <code>to_str</code>, then the two strings are compared using <code>obj.==</code>.</p>

<p>Otherwise, returns similarly to <a href="String.html#method-i-eql-3F"><code>String#eql?</code></a>, comparing length and content.</p>
          
          

          
          <div class="method-source-code" id="3D-3D-3D-source">
            <pre>VALUE
rb_str_equal(VALUE str1, VALUE str2)
{
    if (str1 == str2) return Qtrue;
    if (!RB_TYPE_P(str2, T_STRING)) {
        if (!rb_respond_to(str2, idTo_str)) {
            return Qfalse;
        }
        return rb_equal(str2, str1);
    }
    return rb_str_eql_internal(str1, str2);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Match—If <em>obj</em> is a <a href="Regexp.html"><code>Regexp</code></a>, use it as a pattern to match against <em>str</em>,and returns the position the match starts, or <code>nil</code> if there is no match. Otherwise, invokes <em>obj.=~</em>, passing <em>str</em> as an argument. The default <code>=~</code> in <a href="Object.html"><code>Object</code></a> returns <code>nil</code>.</p>

<p>Note: <code>str =~ regexp</code> is not the same as <code>regexp =~ str</code>. Strings captured from named capture groups are assigned to local variables only in the second case.</p>

<pre class="ruby"><span class="ruby-string">&quot;cat o&#39; 9 tails&quot;</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp">/\d/</span>   <span class="ruby-comment">#=&gt; 7</span>
<span class="ruby-string">&quot;cat o&#39; 9 tails&quot;</span> <span class="ruby-operator">=~</span> <span class="ruby-value">9</span>      <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="3D~-source">
            <pre>static VALUE
rb_str_match(VALUE x, VALUE y)
{
    if (SPECIAL_CONST_P(y)) goto generic;
    switch (BUILTIN_TYPE(y)) {
      case T_STRING:
        rb_raise(rb_eTypeError, &quot;type mismatch: String given&quot;);

      case T_REGEXP:
        return rb_reg_match(y, x);

      generic:
      default:
        return rb_funcall(y, idEqTilde, 1, x);
    }
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-5B-5D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            str[index]                 &rarr; new_str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[start, length]         &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[range]                 &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[regexp]                &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[regexp, capture]       &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[match_str]             &rarr; new_str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Element Reference — If passed a single <code>index</code>, returns a substring of one character at that index. If passed a <code>start</code> index and a <code>length</code>, returns a substring containing <code>length</code> characters starting at the <code>start</code> index. If passed a <code>range</code>, its beginning and end are interpreted as offsets delimiting the substring to be returned.</p>

<p>In these three cases, if an index is negative, it is counted from the end of the string.  For the <code>start</code> and <code>range</code> cases the starting index is just before a character and an index matching the string&#39;s size. Additionally, an empty string is returned when the starting index for a character range is at the end of the string.</p>

<p>Returns <code>nil</code> if the initial index falls outside the string or the length is negative.</p>

<p>If a <code>Regexp</code> is supplied, the matching portion of the string is returned.  If a <code>capture</code> follows the regular expression, which may be a capture group index or name, follows the regular expression that component of the <a href="MatchData.html"><code>MatchData</code></a> is returned instead.</p>

<p>If a <code>match_str</code> is given, that string is returned if it occurs in the string.</p>

<p>Returns <code>nil</code> if the regular expression does not match or the match string cannot be found.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;hello there&quot;</span>

<span class="ruby-identifier">a</span>[<span class="ruby-value">1</span>]                   <span class="ruby-comment">#=&gt; &quot;e&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">2</span>, <span class="ruby-value">3</span>]                <span class="ruby-comment">#=&gt; &quot;llo&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">2</span><span class="ruby-operator">..</span><span class="ruby-value">3</span>]                <span class="ruby-comment">#=&gt; &quot;ll&quot;</span>

<span class="ruby-identifier">a</span>[<span class="ruby-value">-3</span>, <span class="ruby-value">2</span>]               <span class="ruby-comment">#=&gt; &quot;er&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">7</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]               <span class="ruby-comment">#=&gt; &quot;her&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">-4</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]              <span class="ruby-comment">#=&gt; &quot;her&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">-2</span><span class="ruby-operator">..</span><span class="ruby-value">-4</span>]              <span class="ruby-comment">#=&gt; &quot;&quot;</span>

<span class="ruby-identifier">a</span>[<span class="ruby-value">11</span>, <span class="ruby-value">0</span>]               <span class="ruby-comment">#=&gt; &quot;&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">11</span>]                  <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">12</span>, <span class="ruby-value">0</span>]               <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">12</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]              <span class="ruby-comment">#=&gt; nil</span>

<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/[aeiou](.)\1/</span>]      <span class="ruby-comment">#=&gt; &quot;ell&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/[aeiou](.)\1/</span>, <span class="ruby-value">0</span>]   <span class="ruby-comment">#=&gt; &quot;ell&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/[aeiou](.)\1/</span>, <span class="ruby-value">1</span>]   <span class="ruby-comment">#=&gt; &quot;l&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/[aeiou](.)\1/</span>, <span class="ruby-value">2</span>]   <span class="ruby-comment">#=&gt; nil</span>

<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/(?&lt;vowel&gt;[aeiou])(?&lt;non_vowel&gt;[^aeiou])/</span>, <span class="ruby-string">&quot;non_vowel&quot;</span>] <span class="ruby-comment">#=&gt; &quot;l&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/(?&lt;vowel&gt;[aeiou])(?&lt;non_vowel&gt;[^aeiou])/</span>, <span class="ruby-string">&quot;vowel&quot;</span>]     <span class="ruby-comment">#=&gt; &quot;e&quot;</span>

<span class="ruby-identifier">a</span>[<span class="ruby-string">&quot;lo&quot;</span>]                <span class="ruby-comment">#=&gt; &quot;lo&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-string">&quot;bye&quot;</span>]               <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="5B-5D-source">
            <pre>static VALUE
rb_str_aref_m(int argc, VALUE *argv, VALUE str)
{
    if (argc == 2) {
        if (RB_TYPE_P(argv[0], T_REGEXP)) {
            return rb_str_subpat(str, argv[0], argv[1]);
        }
        else {
            long beg = NUM2LONG(argv[0]);
            long len = NUM2LONG(argv[1]);
            return rb_str_substr(str, beg, len);
        }
    }
    rb_check_arity(argc, 1, 2);
    return rb_str_aref(str, argv[0]);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-5B-5D-3D" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            str[integer] = new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[integer, integer] = new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[range] = aString
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[regexp] = new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[regexp, integer] = new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[regexp, name] = new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            str[other_str] = new_str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Element Assignment—Replaces some or all of the content of <em>str</em>. The portion of the string affected is determined using the same criteria as <a href="String.html#method-i-5B-5D"><code>String#[]</code></a>. If the replacement string is not the same length as the text it is replacing, the string will be adjusted accordingly. If the regular expression or string is used as the index doesn&#39;t match a position in the string, <a href="IndexError.html"><code>IndexError</code></a> is raised. If the regular expression form is used, the optional second <a href="Integer.html"><code>Integer</code></a> allows you to specify which portion of the match to replace (effectively using the <a href="MatchData.html"><code>MatchData</code></a> indexing rules. The forms that take an <a href="Integer.html"><code>Integer</code></a> will raise an <a href="IndexError.html"><code>IndexError</code></a> if the value is out of range; the <a href="Range.html"><code>Range</code></a> form will raise a <a href="RangeError.html"><code>RangeError</code></a>, and the <a href="Regexp.html"><code>Regexp</code></a> and <a href="String.html"><code>String</code></a> will raise an <a href="IndexError.html"><code>IndexError</code></a> on negative match.</p>
          
          

          
          <div class="method-source-code" id="5B-5D-3D-source">
            <pre>static VALUE
rb_str_aset_m(int argc, VALUE *argv, VALUE str)
{
    if (argc == 3) {
        if (RB_TYPE_P(argv[0], T_REGEXP)) {
            rb_str_subpat_set(str, argv[0], argv[1], argv[2]);
        }
        else {
            rb_str_splice(str, NUM2LONG(argv[0]), NUM2LONG(argv[1]), argv[2]);
        }
        return argv[2];
    }
    rb_check_arity(argc, 2, 3);
    return rb_str_aset(str, argv[0], argv[1]);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns true for a string which has only ASCII characters.</p>

<pre class="ruby"><span class="ruby-string">&quot;abc&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&quot;UTF-8&quot;</span>).<span class="ruby-identifier">ascii_only?</span>          <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;abc\u{6666}&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&quot;UTF-8&quot;</span>).<span class="ruby-identifier">ascii_only?</span>  <span class="ruby-comment">#=&gt; false</span>
</pre>
          
          

          
          <div class="method-source-code" id="ascii_only-3F-source">
            <pre>static VALUE
rb_str_is_ascii_only_p(VALUE str)
{
    int cr = rb_enc_str_coderange(str);

    return cr == ENC_CODERANGE_7BIT ? Qtrue : Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copied string whose encoding is ASCII-8BIT.</p>
          
          

          
          <div class="method-source-code" id="b-source">
            <pre>static VALUE
rb_str_b(VALUE str)
{
    VALUE str2 = str_alloc(rb_cString);
    str_replace_shared_without_enc(str2, str);
    ENC_CODERANGE_CLEAR(str2);
    return str2;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns an array of bytes in <em>str</em>.  This is a shorthand for <code>str.each_byte.to_a</code>.</p>

<p>If a block is given, which is a deprecated form, works the same as <code>each_byte</code>.</p>
          
          

          
          <div class="method-source-code" id="bytes-source">
            <pre>static VALUE
rb_str_bytes(VALUE str)
{
    VALUE ary = WANTARRAY(&quot;bytes&quot;, RSTRING_LEN(str));
    return rb_str_enumerate_bytes(str, ary);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the length of <code>str</code> in bytes.</p>

<pre class="ruby"><span class="ruby-string">&quot;\x80\u3042&quot;</span>.<span class="ruby-identifier">bytesize</span>  <span class="ruby-comment">#=&gt; 4</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">bytesize</span>       <span class="ruby-comment">#=&gt; 5</span>
</pre>
          
          

          
          <div class="method-source-code" id="bytesize-source">
            <pre>static VALUE
rb_str_bytesize(VALUE str)
{
    return LONG2NUM(RSTRING_LEN(str));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-byteslice" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            byteslice(integer)           &rarr; new_str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            byteslice(integer, integer)   &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            byteslice(range)            &rarr; new_str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Byte Reference—If passed a single <a href="Integer.html"><code>Integer</code></a>, returns a substring of one byte at that position. If passed two <a href="Integer.html"><code>Integer</code></a> objects, returns a substring starting at the offset given by the first, and a length given by the second. If given a <a href="Range.html"><code>Range</code></a>, a substring containing bytes at offsets given by the range is returned. In all three cases, if an offset is negative, it is counted from the end of <em>str</em>. Returns <code>nil</code> if the initial offset falls outside the string, the length is negative, or the beginning of the range is greater than the end. The encoding of the resulted string keeps original encoding.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">byteslice</span>(<span class="ruby-value">1</span>)     <span class="ruby-comment">#=&gt; &quot;e&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">byteslice</span>(<span class="ruby-value">-1</span>)    <span class="ruby-comment">#=&gt; &quot;o&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">byteslice</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; &quot;el&quot;</span>
<span class="ruby-string">&quot;\x80\u3042&quot;</span>.<span class="ruby-identifier">byteslice</span>(<span class="ruby-value">1</span>, <span class="ruby-value">3</span>) <span class="ruby-comment">#=&gt; &quot;\u3042&quot;</span>
<span class="ruby-string">&quot;\x03\u3042\xff&quot;</span>.<span class="ruby-identifier">byteslice</span>(<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">3</span>) <span class="ruby-comment">#=&gt; &quot;\u3042&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="byteslice-source">
            <pre>static VALUE
rb_str_byteslice(int argc, VALUE *argv, VALUE str)
{
    if (argc == 2) {
        long beg = NUM2LONG(argv[0]);
        long end = NUM2LONG(argv[1]);
        return str_byte_substr(str, beg, end, TRUE);
    }
    rb_check_arity(argc, 1, 2);
    return str_byte_aref(str, argv[0]);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of <em>str</em> with the first character converted to uppercase and the remainder to lowercase.</p>

<p>See <a href="String.html#method-i-downcase"><code>String#downcase</code></a> for meaning of <code>options</code> and use with different encodings.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">capitalize</span>    <span class="ruby-comment">#=&gt; &quot;Hello&quot;</span>
<span class="ruby-string">&quot;HELLO&quot;</span>.<span class="ruby-identifier">capitalize</span>    <span class="ruby-comment">#=&gt; &quot;Hello&quot;</span>
<span class="ruby-string">&quot;123ABC&quot;</span>.<span class="ruby-identifier">capitalize</span>   <span class="ruby-comment">#=&gt; &quot;123abc&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="capitalize-source">
            <pre>static VALUE
rb_str_capitalize(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    OnigCaseFoldType flags = ONIGENC_CASE_UPCASE | ONIGENC_CASE_TITLECASE;
    VALUE ret;

    flags = check_case_options(argc, argv, flags);
    enc = str_true_enc(str);
    if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return str;
    if (flags&amp;ONIGENC_CASE_ASCII_ONLY) {
        ret = rb_str_new_with_class(str, 0, RSTRING_LEN(str));
        rb_str_ascii_casemap(str, ret, &amp;flags, enc);
    }
    else {
        ret = rb_str_casemap(str, &amp;flags, enc);
    }
    return ret;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-capitalize-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            capitalize!              &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            capitalize!([options])   &rarr; str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Modifies <em>str</em> by converting the first character to uppercase and the remainder to lowercase. Returns <code>nil</code> if no changes are made. There is an exception for modern Georgian (mkhedruli/MTAVRULI), where the result is the same as for <a href="String.html#method-i-downcase"><code>String#downcase</code></a>, to avoid mixed case.</p>

<p>See <a href="String.html#method-i-downcase"><code>String#downcase</code></a> for meaning of <code>options</code> and use with different encodings.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;hello&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">capitalize!</span>   <span class="ruby-comment">#=&gt; &quot;Hello&quot;</span>
<span class="ruby-identifier">a</span>               <span class="ruby-comment">#=&gt; &quot;Hello&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">capitalize!</span>   <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="capitalize-21-source">
            <pre>static VALUE
rb_str_capitalize_bang(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    OnigCaseFoldType flags = ONIGENC_CASE_UPCASE | ONIGENC_CASE_TITLECASE;

    flags = check_case_options(argc, argv, flags);
    str_modify_keep_cr(str);
    enc = str_true_enc(str);
    if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return Qnil;
    if (flags&amp;ONIGENC_CASE_ASCII_ONLY)
        rb_str_ascii_casemap(str, str, &amp;flags, enc);
    else
        str_shared_replace(str, rb_str_casemap(str, &amp;flags, enc));

    if (ONIGENC_CASE_MODIFIED&amp;flags) return str;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-casecmp" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            casecmp(other_str)   &rarr; -1, 0, +1, or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Case-insensitive version of String#&lt;=&gt;. Currently, case-insensitivity only works on characters A-Z/a-z, not all of Unicode. This is different from <a href="String.html#method-i-casecmp-3F"><code>String#casecmp?</code></a>.</p>

<pre class="ruby"><span class="ruby-string">&quot;aBcDeF&quot;</span>.<span class="ruby-identifier">casecmp</span>(<span class="ruby-string">&quot;abcde&quot;</span>)     <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-string">&quot;aBcDeF&quot;</span>.<span class="ruby-identifier">casecmp</span>(<span class="ruby-string">&quot;abcdef&quot;</span>)    <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-string">&quot;aBcDeF&quot;</span>.<span class="ruby-identifier">casecmp</span>(<span class="ruby-string">&quot;abcdefg&quot;</span>)   <span class="ruby-comment">#=&gt; -1</span>
<span class="ruby-string">&quot;abcdef&quot;</span>.<span class="ruby-identifier">casecmp</span>(<span class="ruby-string">&quot;ABCDEF&quot;</span>)    <span class="ruby-comment">#=&gt; 0</span>
</pre>

<p><code>nil</code> is returned if the two strings have incompatible encodings, or if <code>other_str</code> is not a string.</p>

<pre class="ruby"><span class="ruby-string">&quot;foo&quot;</span>.<span class="ruby-identifier">casecmp</span>(<span class="ruby-value">2</span>)   <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-string">&quot;\u{e4 f6 fc}&quot;</span>.<span class="ruby-identifier">encode</span>(<span class="ruby-string">&quot;ISO-8859-1&quot;</span>).<span class="ruby-identifier">casecmp</span>(<span class="ruby-string">&quot;\u{c4 d6 dc}&quot;</span>)   <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="casecmp-source">
            <pre>static VALUE
rb_str_casecmp(VALUE str1, VALUE str2)
{
    VALUE s = rb_check_string_type(str2);
    if (NIL_P(s)) {
        return Qnil;
    }
    return str_casecmp(str1, s);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns <code>true</code> if <code>str</code> and <code>other_str</code> are equal after Unicode case folding, <code>false</code> if they are not equal.</p>

<pre class="ruby"><span class="ruby-string">&quot;aBcDeF&quot;</span>.<span class="ruby-identifier">casecmp?</span>(<span class="ruby-string">&quot;abcde&quot;</span>)     <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot;aBcDeF&quot;</span>.<span class="ruby-identifier">casecmp?</span>(<span class="ruby-string">&quot;abcdef&quot;</span>)    <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;aBcDeF&quot;</span>.<span class="ruby-identifier">casecmp?</span>(<span class="ruby-string">&quot;abcdefg&quot;</span>)   <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot;abcdef&quot;</span>.<span class="ruby-identifier">casecmp?</span>(<span class="ruby-string">&quot;ABCDEF&quot;</span>)    <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;\u{e4 f6 fc}&quot;</span>.<span class="ruby-identifier">casecmp?</span>(<span class="ruby-string">&quot;\u{c4 d6 dc}&quot;</span>)   <span class="ruby-comment">#=&gt; true</span>
</pre>

<p><code>nil</code> is returned if the two strings have incompatible encodings, or if <code>other_str</code> is not a string.</p>

<pre class="ruby"><span class="ruby-string">&quot;foo&quot;</span>.<span class="ruby-identifier">casecmp?</span>(<span class="ruby-value">2</span>)   <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-string">&quot;\u{e4 f6 fc}&quot;</span>.<span class="ruby-identifier">encode</span>(<span class="ruby-string">&quot;ISO-8859-1&quot;</span>).<span class="ruby-identifier">casecmp?</span>(<span class="ruby-string">&quot;\u{c4 d6 dc}&quot;</span>)   <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="casecmp-3F-source">
            <pre>static VALUE
rb_str_casecmp_p(VALUE str1, VALUE str2)
{
    VALUE s = rb_check_string_type(str2);
    if (NIL_P(s)) {
        return Qnil;
    }
    return str_casecmp_p(str1, s);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-center" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            center(width, padstr=&#39; &#39;)   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Centers <code>str</code> in <code>width</code>.  If <code>width</code> is greater than the length of <code>str</code>, returns a new <a href="String.html"><code>String</code></a> of length <code>width</code> with <code>str</code> centered and padded with <code>padstr</code>; otherwise, returns <code>str</code>.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">center</span>(<span class="ruby-value">4</span>)         <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">center</span>(<span class="ruby-value">20</span>)        <span class="ruby-comment">#=&gt; &quot;       hello        &quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">center</span>(<span class="ruby-value">20</span>, <span class="ruby-string">&#39;123&#39;</span>) <span class="ruby-comment">#=&gt; &quot;1231231hello12312312&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="center-source">
            <pre>static VALUE
rb_str_center(int argc, VALUE *argv, VALUE str)
{
    return rb_str_justify(argc, argv, str, &#39;c&#39;);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns an array of characters in <em>str</em>.  This is a shorthand for <code>str.each_char.to_a</code>.</p>

<p>If a block is given, which is a deprecated form, works the same as <code>each_char</code>.</p>
          
          

          
          <div class="method-source-code" id="chars-source">
            <pre>static VALUE
rb_str_chars(VALUE str)
{
    VALUE ary = WANTARRAY(&quot;chars&quot;, rb_str_strlen(str));
    return rb_str_enumerate_chars(str, ary);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a new <a href="String.html"><code>String</code></a> with the given record separator removed from the end of <em>str</em> (if present). If <code>$/</code> has not been changed from the default Ruby record separator, then <code>chomp</code> also removes carriage return characters (that is it will remove <code>\n</code>, <code>\r</code>, and <code>\r\n</code>). If <code>$/</code> is an empty string, it will remove all trailing newlines from the string.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">chomp</span>                <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello\n&quot;</span>.<span class="ruby-identifier">chomp</span>              <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello\r\n&quot;</span>.<span class="ruby-identifier">chomp</span>            <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello\n\r&quot;</span>.<span class="ruby-identifier">chomp</span>            <span class="ruby-comment">#=&gt; &quot;hello\n&quot;</span>
<span class="ruby-string">&quot;hello\r&quot;</span>.<span class="ruby-identifier">chomp</span>              <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello \n there&quot;</span>.<span class="ruby-identifier">chomp</span>       <span class="ruby-comment">#=&gt; &quot;hello \n there&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">chomp</span>(<span class="ruby-string">&quot;llo&quot;</span>)         <span class="ruby-comment">#=&gt; &quot;he&quot;</span>
<span class="ruby-string">&quot;hello\r\n\r\n&quot;</span>.<span class="ruby-identifier">chomp</span>(<span class="ruby-string">&#39;&#39;</span>)    <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello\r\n\r\r\n&quot;</span>.<span class="ruby-identifier">chomp</span>(<span class="ruby-string">&#39;&#39;</span>)  <span class="ruby-comment">#=&gt; &quot;hello\r\n\r&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="chomp-source">
            <pre>static VALUE
rb_str_chomp(int argc, VALUE *argv, VALUE str)
{
    VALUE rs = chomp_rs(argc, argv);
    if (NIL_P(rs)) return rb_str_dup(str);
    return rb_str_subseq(str, 0, chompped_length(str, rs));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-chomp-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            chomp!(separator=$/)   &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Modifies <em>str</em> in place as described for <a href="String.html#method-i-chomp"><code>String#chomp</code></a>, returning <em>str</em>, or <code>nil</code> if no modifications were made.</p>
          
          

          
          <div class="method-source-code" id="chomp-21-source">
            <pre>static VALUE
rb_str_chomp_bang(int argc, VALUE *argv, VALUE str)
{
    VALUE rs;
    str_modifiable(str);
    if (RSTRING_LEN(str) == 0) return Qnil;
    rs = chomp_rs(argc, argv);
    if (NIL_P(rs)) return Qnil;
    return rb_str_chomp_string(str, rs);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a new <a href="String.html"><code>String</code></a> with the last character removed.  If the string ends with <code>\r\n</code>, both characters are removed. Applying <code>chop</code> to an empty string returns an empty string. <a href="String.html#method-i-chomp"><code>String#chomp</code></a> is often a safer alternative, as it leaves the string unchanged if it doesn&#39;t end in a record separator.</p>

<pre class="ruby"><span class="ruby-string">&quot;string\r\n&quot;</span>.<span class="ruby-identifier">chop</span>   <span class="ruby-comment">#=&gt; &quot;string&quot;</span>
<span class="ruby-string">&quot;string\n\r&quot;</span>.<span class="ruby-identifier">chop</span>   <span class="ruby-comment">#=&gt; &quot;string\n&quot;</span>
<span class="ruby-string">&quot;string\n&quot;</span>.<span class="ruby-identifier">chop</span>     <span class="ruby-comment">#=&gt; &quot;string&quot;</span>
<span class="ruby-string">&quot;string&quot;</span>.<span class="ruby-identifier">chop</span>       <span class="ruby-comment">#=&gt; &quot;strin&quot;</span>
<span class="ruby-string">&quot;x&quot;</span>.<span class="ruby-identifier">chop</span>.<span class="ruby-identifier">chop</span>       <span class="ruby-comment">#=&gt; &quot;&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="chop-source">
            <pre>static VALUE
rb_str_chop(VALUE str)
{
    return rb_str_subseq(str, 0, chopped_length(str));
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Processes <em>str</em> as for <a href="String.html#method-i-chop"><code>String#chop</code></a>, returning <em>str</em>, or <code>nil</code> if <em>str</em> is the empty string.  See also <a href="String.html#method-i-chomp-21"><code>String#chomp!</code></a>.</p>
          
          

          
          <div class="method-source-code" id="chop-21-source">
            <pre>static VALUE
rb_str_chop_bang(VALUE str)
{
    str_modify_keep_cr(str);
    if (RSTRING_LEN(str) &gt; 0) {
        long len;
        len = chopped_length(str);
        STR_SET_LEN(str, len);
        TERM_FILL(&amp;RSTRING_PTR(str)[len], TERM_LEN(str));
        if (ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) {
            ENC_CODERANGE_CLEAR(str);
        }
        return str;
    }
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a one-character string at the beginning of the string.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;abcde&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">chr</span>    <span class="ruby-comment">#=&gt; &quot;a&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="chr-source">
            <pre>static VALUE
rb_str_chr(VALUE str)
{
    return rb_str_substr(str, 0, 1);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Makes string empty.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;abcde&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">clear</span>    <span class="ruby-comment">#=&gt; &quot;&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="clear-source">
            <pre>static VALUE
rb_str_clear(VALUE str)
{
    str_discard(str);
    STR_SET_EMBED(str);
    STR_SET_EMBED_LEN(str, 0);
    RSTRING_PTR(str)[0] = 0;
    if (rb_enc_asciicompat(STR_ENC_GET(str)))
        ENC_CODERANGE_SET(str, ENC_CODERANGE_7BIT);
    else
        ENC_CODERANGE_SET(str, ENC_CODERANGE_VALID);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns an array of the <a href="Integer.html"><code>Integer</code></a> ordinals of the characters in <em>str</em>.  This is a shorthand for <code>str.each_codepoint.to_a</code>.</p>

<p>If a block is given, which is a deprecated form, works the same as <code>each_codepoint</code>.</p>
          
          

          
          <div class="method-source-code" id="codepoints-source">
            <pre>static VALUE
rb_str_codepoints(VALUE str)
{
    VALUE ary = WANTARRAY(&quot;codepoints&quot;, rb_str_strlen(str));
    return rb_str_enumerate_codepoints(str, ary);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-concat" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            concat(obj1, obj2, ...)          &rarr; str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Concatenates the given object(s) to <em>str</em>. If an object is an <a href="Integer.html"><code>Integer</code></a>, it is considered a codepoint and converted to a character before concatenation.</p>

<p><code>concat</code> can take multiple arguments, and all the arguments are concatenated in order.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;hello &quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-string">&quot;world&quot;</span>, <span class="ruby-value">33</span>)      <span class="ruby-comment">#=&gt; &quot;hello world!&quot;</span>
<span class="ruby-identifier">a</span>                          <span class="ruby-comment">#=&gt; &quot;hello world!&quot;</span>

<span class="ruby-identifier">b</span> = <span class="ruby-string">&quot;sn&quot;</span>
<span class="ruby-identifier">b</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-string">&quot;_&quot;</span>, <span class="ruby-identifier">b</span>, <span class="ruby-string">&quot;_&quot;</span>, <span class="ruby-identifier">b</span>)   <span class="ruby-comment">#=&gt; &quot;sn_sn_sn&quot;</span>
</pre>

<p>See also <a href="String.html#method-i-3C-3C"><code>String#<<</code></a>, which takes a single argument.</p>
          
          

          
          <div class="method-source-code" id="concat-source">
            <pre>static VALUE
rb_str_concat_multi(int argc, VALUE *argv, VALUE str)
{
    str_modifiable(str);

    if (argc == 1) {
        return rb_str_concat(str, argv[0]);
    }
    else if (argc &gt; 1) {
        int i;
        VALUE arg_str = rb_str_tmp_new(0);
        rb_enc_copy(arg_str, str);
        for (i = 0; i &lt; argc; i++) {
            rb_str_concat(arg_str, argv[i]);
        }
        rb_str_buf_append(str, arg_str);
    }

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

        

        
      </div>

    
      <div id="method-i-count" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            count([other_str]+)   &rarr; integer
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Each <code>other_str</code> parameter defines a set of characters to count.  The intersection of these sets defines the characters to count in <code>str</code>.  Any <code>other_str</code> that starts with a caret <code>^</code> is negated.  The sequence <code>c1-c2</code> means all characters between c1 and c2.  The backslash character <code>\</code> can be used to escape <code>^</code> or <code>-</code> and is otherwise ignored unless it appears at the end of a sequence or the end of a <code>other_str</code>.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;hello world&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;lo&quot;</span>                   <span class="ruby-comment">#=&gt; 5</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;lo&quot;</span>, <span class="ruby-string">&quot;o&quot;</span>              <span class="ruby-comment">#=&gt; 2</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;hello&quot;</span>, <span class="ruby-string">&quot;^l&quot;</span>          <span class="ruby-comment">#=&gt; 4</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;ej-m&quot;</span>                 <span class="ruby-comment">#=&gt; 4</span>

<span class="ruby-string">&quot;hello^world&quot;</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;\\^aeiou&quot;</span> <span class="ruby-comment">#=&gt; 4</span>
<span class="ruby-string">&quot;hello-world&quot;</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;a\\-eo&quot;</span>   <span class="ruby-comment">#=&gt; 4</span>

<span class="ruby-identifier">c</span> = <span class="ruby-string">&quot;hello world\\r\\n&quot;</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;\\&quot;</span>                   <span class="ruby-comment">#=&gt; 2</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;\\A&quot;</span>                  <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">count</span> <span class="ruby-string">&quot;X-\\w&quot;</span>                <span class="ruby-comment">#=&gt; 3</span>
</pre>
          
          

          
          <div class="method-source-code" id="count-source">
            <pre>static VALUE
rb_str_count(int argc, VALUE *argv, VALUE str)
{
    char table[TR_TABLE_SIZE];
    rb_encoding *enc = 0;
    VALUE del = 0, nodel = 0, tstr;
    char *s, *send;
    int i;
    int ascompat;

    rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);

    tstr = argv[0];
    StringValue(tstr);
    enc = rb_enc_check(str, tstr);
    if (argc == 1) {
        const char *ptstr;
        if (RSTRING_LEN(tstr) == 1 &amp;&amp; rb_enc_asciicompat(enc) &amp;&amp;
            (ptstr = RSTRING_PTR(tstr),
             ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, (const unsigned char *)ptstr, (const unsigned char *)ptstr+1)) &amp;&amp;
            !is_broken_string(str)) {
            int n = 0;
            int clen;
            unsigned char c = rb_enc_codepoint_len(ptstr, ptstr+1, &amp;clen, enc);

            s = RSTRING_PTR(str);
            if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0);
            send = RSTRING_END(str);
            while (s &lt; send) {
                if (*(unsigned char*)s++ == c) n++;
            }
            return INT2NUM(n);
        }
    }

    tr_setup_table(tstr, table, TRUE, &amp;del, &amp;nodel, enc);
    for (i=1; i&lt;argc; i++) {
        tstr = argv[i];
        StringValue(tstr);
        enc = rb_enc_check(str, tstr);
        tr_setup_table(tstr, table, FALSE, &amp;del, &amp;nodel, enc);
    }

    s = RSTRING_PTR(str);
    if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0);
    send = RSTRING_END(str);
    ascompat = rb_enc_asciicompat(enc);
    i = 0;
    while (s &lt; send) {
        unsigned int c;

        if (ascompat &amp;&amp; (c = *(unsigned char*)s) &lt; 0x80) {
            if (table[c]) {
                i++;
            }
            s++;
        }
        else {
            int clen;
            c = rb_enc_codepoint_len(s, send, &amp;clen, enc);
            if (tr_find(c, table, del, nodel)) {
                i++;
            }
            s += clen;
        }
    }

    return INT2NUM(i);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the string generated by calling <code>crypt(3)</code> standard library function with <code>str</code> and <code>salt_str</code>, in this order, as its arguments.  Please do not use this method any longer.  It is legacy; provided only for backward compatibility with ruby scripts in earlier days.  It is bad to use in contemporary programs for several reasons:</p>
<ul><li>
<p>Behaviour of C&#39;s <code>crypt(3)</code> depends on the OS it is run.  The generated string lacks data portability.</p>
</li><li>
<p>On some OSes such as Mac OS, <code>crypt(3)</code> never fails (i.e. silently ends up in unexpected results).</p>
</li><li>
<p>On some OSes such as Mac OS, <code>crypt(3)</code> is not thread safe.</p>
</li><li>
<p>So-called “traditional” usage of <code>crypt(3)</code> is very very very weak.  According to its manpage, Linux&#39;s traditional <code>crypt(3)</code> output has only 2**56 variations; too easy to brute force today.  And this is the default behaviour.</p>
</li><li>
<p>In order to make things robust some OSes implement so-called “modular” usage. To go through, you have to do a complex build-up of the <code>salt_str</code> parameter, by hand. Failure in generation of a proper salt string tends not to yield any errors; typos in parameters are normally not detectable.</p>
<ul><li>
<p>For instance, in the following example, the second invocation of <a href="String.html#method-i-crypt"><code>String#crypt</code></a> is wrong; it has a typo in “round=” (lacks “s”).  However the call does not fail and something unexpected is generated.</p>

<pre class="ruby"><span class="ruby-string">&quot;foo&quot;</span>.<span class="ruby-identifier">crypt</span>(<span class="ruby-string">&quot;$5$rounds=1000$salt$&quot;</span>) <span class="ruby-comment"># OK, proper usage</span>
<span class="ruby-string">&quot;foo&quot;</span>.<span class="ruby-identifier">crypt</span>(<span class="ruby-string">&quot;$5$round=1000$salt$&quot;</span>)  <span class="ruby-comment"># Typo not detected</span>
</pre>
</li></ul>
</li><li>
<p>Even in the “modular” mode, some hash functions are considered archaic and no longer recommended at all; for instance module <code>$1$</code> is officially abandoned by its author: see <a href="http://phk.freebsd.dk/sagas/md5crypt_eol.html">phk.freebsd.dk/sagas/md5crypt_eol.html</a> .  For another instance module <code>$3$</code> is considered completely broken: see the manpage of FreeBSD.</p>
</li><li>
<p>On some OS such as Mac OS, there is no modular mode. Yet, as written above, <code>crypt(3)</code> on Mac OS never fails. This means even if you build up a proper salt string it generates a traditional DES hash anyways, and there is no way for you to be aware of.</p>

<pre class="ruby"><span class="ruby-string">&quot;foo&quot;</span>.<span class="ruby-identifier">crypt</span>(<span class="ruby-string">&quot;$5$rounds=1000$salt$&quot;</span>) <span class="ruby-comment"># =&gt; &quot;$5fNPQMxC5j6.&quot;</span>
</pre>
</li></ul>

<p>If for some reason you cannot migrate to other secure contemporary password hashing algorithms, install the string-crypt gem and <code>require &#39;string/crypt&#39;</code> to continue using it.</p>
          
          

          
          <div class="method-source-code" id="crypt-source">
            <pre>static VALUE
rb_str_crypt(VALUE str, VALUE salt)
{
#ifdef HAVE_CRYPT_R
    VALUE databuf;
    struct crypt_data *data;
#   define CRYPT_END() ALLOCV_END(databuf)
#else
    extern char *crypt(const char *, const char *);
#   define CRYPT_END() (void)0
#endif
    VALUE result;
    const char *s, *saltp;
    char *res;
#ifdef BROKEN_CRYPT
    char salt_8bit_clean[3];
#endif

    StringValue(salt);
    mustnot_wchar(str);
    mustnot_wchar(salt);
    if (RSTRING_LEN(salt) &lt; 2) {
      short_salt:
        rb_raise(rb_eArgError, &quot;salt too short (need &gt;=2 bytes)&quot;);
    }

    s = StringValueCStr(str);
    saltp = RSTRING_PTR(salt);
    if (!saltp[0] || !saltp[1]) goto short_salt;
#ifdef BROKEN_CRYPT
    if (!ISASCII((unsigned char)saltp[0]) || !ISASCII((unsigned char)saltp[1])) {
        salt_8bit_clean[0] = saltp[0] &amp; 0x7f;
        salt_8bit_clean[1] = saltp[1] &amp; 0x7f;
        salt_8bit_clean[2] = &#39;\0&#39;;
        saltp = salt_8bit_clean;
    }
#endif
#ifdef HAVE_CRYPT_R
    data = ALLOCV(databuf, sizeof(struct crypt_data));
# ifdef HAVE_STRUCT_CRYPT_DATA_INITIALIZED
    data-&gt;initialized = 0;
# endif
    res = crypt_r(s, saltp, data);
#else
    res = crypt(s, saltp);
#endif
    if (!res) {
        int err = errno;
        CRYPT_END();
        rb_syserr_fail(err, &quot;crypt&quot;);
    }
    result = rb_str_new_cstr(res);
    CRYPT_END();
    return result;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-delete" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            delete([other_str]+)   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns a copy of <em>str</em> with all characters in the intersection of its arguments deleted. Uses the same rules for building the set of characters as <a href="String.html#method-i-count"><code>String#count</code></a>.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete</span> <span class="ruby-string">&quot;l&quot;</span>,<span class="ruby-string">&quot;lo&quot;</span>        <span class="ruby-comment">#=&gt; &quot;heo&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete</span> <span class="ruby-string">&quot;lo&quot;</span>            <span class="ruby-comment">#=&gt; &quot;he&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete</span> <span class="ruby-string">&quot;aeiou&quot;</span>, <span class="ruby-string">&quot;^e&quot;</span>   <span class="ruby-comment">#=&gt; &quot;hell&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete</span> <span class="ruby-string">&quot;ej-m&quot;</span>          <span class="ruby-comment">#=&gt; &quot;ho&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="delete-source">
            <pre>static VALUE
rb_str_delete(int argc, VALUE *argv, VALUE str)
{
    str = rb_str_dup(str);
    rb_str_delete_bang(argc, argv, str);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-delete-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            delete!([other_str]+)   &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Performs a <code>delete</code> operation in place, returning <em>str</em>, or <code>nil</code> if <em>str</em> was not modified.</p>
          
          

          
          <div class="method-source-code" id="delete-21-source">
            <pre>static VALUE
rb_str_delete_bang(int argc, VALUE *argv, VALUE str)
{
    char squeez[TR_TABLE_SIZE];
    rb_encoding *enc = 0;
    char *s, *send, *t;
    VALUE del = 0, nodel = 0;
    int modify = 0;
    int i, ascompat, cr;

    if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return Qnil;
    rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
    for (i=0; i&lt;argc; i++) {
        VALUE s = argv[i];

        StringValue(s);
        enc = rb_enc_check(str, s);
        tr_setup_table(s, squeez, i==0, &amp;del, &amp;nodel, enc);
    }

    str_modify_keep_cr(str);
    ascompat = rb_enc_asciicompat(enc);
    s = t = RSTRING_PTR(str);
    send = RSTRING_END(str);
    cr = ascompat ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
    while (s &lt; send) {
        unsigned int c;
        int clen;

        if (ascompat &amp;&amp; (c = *(unsigned char*)s) &lt; 0x80) {
            if (squeez[c]) {
                modify = 1;
            }
            else {
                if (t != s) *t = c;
                t++;
            }
            s++;
        }
        else {
            c = rb_enc_codepoint_len(s, send, &amp;clen, enc);

            if (tr_find(c, squeez, del, nodel)) {
                modify = 1;
            }
            else {
                if (t != s) rb_enc_mbcput(c, t, enc);
                t += clen;
                if (cr == ENC_CODERANGE_7BIT) cr = ENC_CODERANGE_VALID;
            }
            s += clen;
        }
    }
    TERM_FILL(t, TERM_LEN(str));
    STR_SET_LEN(str, t - RSTRING_PTR(str));
    ENC_CODERANGE_SET(str, cr);

    if (modify) return str;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of <em>str</em> with leading <code>prefix</code> deleted.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete_prefix</span>(<span class="ruby-string">&quot;hel&quot;</span>) <span class="ruby-comment">#=&gt; &quot;lo&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete_prefix</span>(<span class="ruby-string">&quot;llo&quot;</span>) <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="delete_prefix-source">
            <pre>static VALUE
rb_str_delete_prefix(VALUE str, VALUE prefix)
{
    long prefixlen;

    prefixlen = deleted_prefix_length(str, prefix);
    if (prefixlen &lt;= 0) return rb_str_dup(str);

    return rb_str_subseq(str, prefixlen, RSTRING_LEN(str) - prefixlen);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-delete_prefix-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            delete_prefix!(prefix) &rarr; self or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Deletes leading <code>prefix</code> from <em>str</em>, returning <code>nil</code> if no change was made.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete_prefix!</span>(<span class="ruby-string">&quot;hel&quot;</span>) <span class="ruby-comment">#=&gt; &quot;lo&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete_prefix!</span>(<span class="ruby-string">&quot;llo&quot;</span>) <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="delete_prefix-21-source">
            <pre>static VALUE
rb_str_delete_prefix_bang(VALUE str, VALUE prefix)
{
    long prefixlen;
    str_modify_keep_cr(str);

    prefixlen = deleted_prefix_length(str, prefix);
    if (prefixlen &lt;= 0) return Qnil;

    return rb_str_drop_bytes(str, prefixlen);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of <em>str</em> with trailing <code>suffix</code> deleted.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete_suffix</span>(<span class="ruby-string">&quot;llo&quot;</span>) <span class="ruby-comment">#=&gt; &quot;he&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete_suffix</span>(<span class="ruby-string">&quot;hel&quot;</span>) <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="delete_suffix-source">
            <pre>static VALUE
rb_str_delete_suffix(VALUE str, VALUE suffix)
{
    long suffixlen;

    suffixlen = deleted_suffix_length(str, suffix);
    if (suffixlen &lt;= 0) return rb_str_dup(str);

    return rb_str_subseq(str, 0, RSTRING_LEN(str) - suffixlen);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-delete_suffix-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            delete_suffix!(suffix) &rarr; self or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Deletes trailing <code>suffix</code> from <em>str</em>, returning <code>nil</code> if no change was made.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete_suffix!</span>(<span class="ruby-string">&quot;llo&quot;</span>) <span class="ruby-comment">#=&gt; &quot;he&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">delete_suffix!</span>(<span class="ruby-string">&quot;hel&quot;</span>) <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="delete_suffix-21-source">
            <pre>static VALUE
rb_str_delete_suffix_bang(VALUE str, VALUE suffix)
{
    long olen, suffixlen, len;
    str_modifiable(str);

    suffixlen = deleted_suffix_length(str, suffix);
    if (suffixlen &lt;= 0) return Qnil;

    olen = RSTRING_LEN(str);
    str_modify_keep_cr(str);
    len = olen - suffixlen;
    STR_SET_LEN(str, len);
    TERM_FILL(&amp;RSTRING_PTR(str)[len], TERM_LEN(str));
    if (ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) {
        ENC_CODERANGE_CLEAR(str);
    }
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of <em>str</em> with all uppercase letters replaced with their lowercase counterparts. Which letters exactly are replaced, and by which other letters, depends on the presence or absence of options, and on the <code>encoding</code> of the string.</p>

<p>The meaning of the <code>options</code> is as follows:</p>
<dl class="rdoc-list note-list"><dt>No option 
<dd>
<p>Full Unicode case mapping, suitable for most languages (see :turkic and :lithuanian options below for exceptions). Context-dependent case mapping as described in Table 3-14 of the Unicode standard is currently not supported.</p>
</dd><dt>:ascii 
<dd>
<p>Only the ASCII region, i.e. the characters “A&#39;&#39; to “Z&#39;&#39; and “a&#39;&#39; to “z&#39;&#39;, are affected. This option cannot be combined with any other option.</p>
</dd><dt>:turkic 
<dd>
<p>Full Unicode case mapping, adapted for Turkic languages (Turkish, Azerbaijani, …). This means that upper case I is mapped to lower case dotless i, and so on.</p>
</dd><dt>:lithuanian 
<dd>
<p>Currently, just full Unicode case mapping. In the future, full Unicode case mapping adapted for Lithuanian (keeping the dot on the lower case i even if there is an accent on top).</p>
</dd><dt>:fold 
<dd>
<p>Only available on <code>downcase</code> and <code>downcase!</code>. Unicode case <strong>folding</strong>, which is more far-reaching than Unicode case mapping. This option currently cannot be combined with any other option (i.e. there is currently no variant for turkic languages).</p>
</dd></dl>

<p>Please note that several assumptions that are valid for ASCII-only case conversions do not hold for more general case conversions. For example, the length of the result may not be the same as the length of the input (neither in characters nor in bytes), some roundtrip assumptions (e.g. str.downcase == str.upcase.downcase) may not apply, and Unicode normalization (i.e. <a href="String.html#method-i-unicode_normalize"><code>String#unicode_normalize</code></a>) is not necessarily maintained by case mapping operations.</p>

<p>Non-ASCII case mapping/folding is currently supported for UTF-8, UTF-16BE/LE, UTF-32BE/LE, and ISO-8859-1~16 Strings/Symbols. This support will be extended to other encodings.</p>

<pre class="ruby"><span class="ruby-string">&quot;hEllO&quot;</span>.<span class="ruby-identifier">downcase</span>   <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="downcase-source">
            <pre>static VALUE
rb_str_downcase(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    OnigCaseFoldType flags = ONIGENC_CASE_DOWNCASE;
    VALUE ret;

    flags = check_case_options(argc, argv, flags);
    enc = str_true_enc(str);
    if (case_option_single_p(flags, enc, str)) {
        ret = rb_str_new_with_class(str, RSTRING_PTR(str), RSTRING_LEN(str));
        str_enc_copy(ret, str);
        downcase_single(ret);
    }
    else if (flags&amp;ONIGENC_CASE_ASCII_ONLY) {
        ret = rb_str_new_with_class(str, 0, RSTRING_LEN(str));
        rb_str_ascii_casemap(str, ret, &amp;flags, enc);
    }
    else {
        ret = rb_str_casemap(str, &amp;flags, enc);
    }

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

        

        
      </div>

    
      <div id="method-i-downcase-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            downcase!             &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            downcase!([options])  &rarr; str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Downcases the contents of <em>str</em>, returning <code>nil</code> if no changes were made.</p>

<p>See <a href="String.html#method-i-downcase"><code>String#downcase</code></a> for meaning of <code>options</code> and use with different encodings.</p>
          
          

          
          <div class="method-source-code" id="downcase-21-source">
            <pre>static VALUE
rb_str_downcase_bang(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    OnigCaseFoldType flags = ONIGENC_CASE_DOWNCASE;

    flags = check_case_options(argc, argv, flags);
    str_modify_keep_cr(str);
    enc = str_true_enc(str);
    if (case_option_single_p(flags, enc, str)) {
        if (downcase_single(str))
            flags |= ONIGENC_CASE_MODIFIED;
    }
    else if (flags&amp;ONIGENC_CASE_ASCII_ONLY)
        rb_str_ascii_casemap(str, str, &amp;flags, enc);
    else
        str_shared_replace(str, rb_str_casemap(str, &amp;flags, enc));

    if (ONIGENC_CASE_MODIFIED&amp;flags) return str;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a quoted version of the string with all non-printing characters replaced by <code>\xHH</code> notation and all special characters escaped.</p>

<p>This method can be used for round-trip: if the resulting <code>new_str</code> is eval&#39;ed, it will produce the original string.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello \n &#39;&#39;&quot;</span>.<span class="ruby-identifier">dump</span>     <span class="ruby-comment">#=&gt; &quot;\&quot;hello \\n &#39;&#39;\&quot;&quot;</span>
<span class="ruby-string">&quot;\f\x00\xff\\\&quot;&quot;</span>.<span class="ruby-identifier">dump</span>  <span class="ruby-comment">#=&gt; &quot;\&quot;\\f\\x00\\xFF\\\\\\\&quot;\&quot;&quot;</span>
</pre>

<p>See also <a href="String.html#method-i-undump"><code>String#undump</code></a>.</p>
          
          

          
          <div class="method-source-code" id="dump-source">
            <pre>VALUE
rb_str_dump(VALUE str)
{
    int encidx = rb_enc_get_index(str);
    rb_encoding *enc = rb_enc_from_index(encidx);
    long len;
    const char *p, *pend;
    char *q, *qend;
    VALUE result;
    int u8 = (encidx == rb_utf8_encindex());
    static const char nonascii_suffix[] = &quot;.dup.force_encoding(\&quot;%s\&quot;)&quot;;

    len = 2;                    /* &quot;&quot; */
    if (!rb_enc_asciicompat(enc)) {
        len += strlen(nonascii_suffix) - rb_strlen_lit(&quot;%s&quot;);
        len += strlen(enc-&gt;name);
    }

    p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str);
    while (p &lt; pend) {
        int clen;
        unsigned char c = *p++;

        switch (c) {
          case &#39;&quot;&#39;:  case &#39;\\&#39;:
          case &#39;\n&#39;: case &#39;\r&#39;:
          case &#39;\t&#39;: case &#39;\f&#39;:
          case &#39;\013&#39;: case &#39;\010&#39;: case &#39;\007&#39;: case &#39;\033&#39;:
            clen = 2;
            break;

          case &#39;#&#39;:
            clen = IS_EVSTR(p, pend) ? 2 : 1;
            break;

          default:
            if (ISPRINT(c)) {
                clen = 1;
            }
            else {
                if (u8 &amp;&amp; c &gt; 0x7F) { /* \u notation */
                    int n = rb_enc_precise_mbclen(p-1, pend, enc);
                    if (MBCLEN_CHARFOUND_P(n)) {
                        unsigned int cc = rb_enc_mbc_to_codepoint(p-1, pend, enc);
                        if (cc &lt;= 0xFFFF)
                            clen = 6;  /* \uXXXX */
                        else if (cc &lt;= 0xFFFFF)
                            clen = 9;  /* \u{XXXXX} */
                        else
                            clen = 10; /* \u{XXXXXX} */
                        p += MBCLEN_CHARFOUND_LEN(n)-1;
                        break;
                    }
                }
                clen = 4;     /* \xNN */
            }
            break;
        }

        if (clen &gt; LONG_MAX - len) {
            rb_raise(rb_eRuntimeError, &quot;string size too big&quot;);
        }
        len += clen;
    }

    result = rb_str_new_with_class(str, 0, len);
    p = RSTRING_PTR(str); pend = p + RSTRING_LEN(str);
    q = RSTRING_PTR(result); qend = q + len + 1;

    *q++ = &#39;&quot;&#39;;
    while (p &lt; pend) {
        unsigned char c = *p++;

        if (c == &#39;&quot;&#39; || c == &#39;\\&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = c;
        }
        else if (c == &#39;#&#39;) {
            if (IS_EVSTR(p, pend)) *q++ = &#39;\\&#39;;
            *q++ = &#39;#&#39;;
        }
        else if (c == &#39;\n&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = &#39;n&#39;;
        }
        else if (c == &#39;\r&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = &#39;r&#39;;
        }
        else if (c == &#39;\t&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = &#39;t&#39;;
        }
        else if (c == &#39;\f&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = &#39;f&#39;;
        }
        else if (c == &#39;\013&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = &#39;v&#39;;
        }
        else if (c == &#39;\010&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = &#39;b&#39;;
        }
        else if (c == &#39;\007&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = &#39;a&#39;;
        }
        else if (c == &#39;\033&#39;) {
            *q++ = &#39;\\&#39;;
            *q++ = &#39;e&#39;;
        }
        else if (ISPRINT(c)) {
            *q++ = c;
        }
        else {
            *q++ = &#39;\\&#39;;
            if (u8) {
                int n = rb_enc_precise_mbclen(p-1, pend, enc) - 1;
                if (MBCLEN_CHARFOUND_P(n)) {
                    int cc = rb_enc_mbc_to_codepoint(p-1, pend, enc);
                    p += n;
                    if (cc &lt;= 0xFFFF)
                        snprintf(q, qend-q, &quot;u%04X&quot;, cc);    /* \uXXXX */
                    else
                        snprintf(q, qend-q, &quot;u{%X}&quot;, cc);  /* \u{XXXXX} or \u{XXXXXX} */
                    q += strlen(q);
                    continue;
                }
            }
            snprintf(q, qend-q, &quot;x%02X&quot;, c);
            q += 3;
        }
    }
    *q++ = &#39;&quot;&#39;;
    *q = &#39;\0&#39;;
    if (!rb_enc_asciicompat(enc)) {
        snprintf(q, qend-q, nonascii_suffix, enc-&gt;name);
        encidx = rb_ascii8bit_encindex();
    }
    /* result from dump is ASCII */
    rb_enc_associate_index(result, encidx);
    ENC_CODERANGE_SET(result, ENC_CODERANGE_7BIT);
    return result;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Passes each byte in <em>str</em> to the given block, or returns an enumerator if no block is given.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">each_byte</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-identifier">c</span>, <span class="ruby-string">&#39; &#39;</span> }
</pre>

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

<pre>104 101 108 108 111</pre>
          
          

          
          <div class="method-source-code" id="each_byte-source">
            <pre>static VALUE
rb_str_each_byte(VALUE str)
{
    RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_byte_size);
    return rb_str_enumerate_bytes(str, 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-each_char" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            each_char {|cstr| block }    &rarr; str
          </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>Passes each character in <em>str</em> to the given block, or returns an enumerator if no block is given.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">each_char</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-identifier">c</span>, <span class="ruby-string">&#39; &#39;</span> }
</pre>

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

<pre class="ruby"><span class="ruby-identifier">h</span> <span class="ruby-identifier">e</span> <span class="ruby-identifier">l</span> <span class="ruby-identifier">l</span> <span class="ruby-identifier">o</span>
</pre>
          
          

          
          <div class="method-source-code" id="each_char-source">
            <pre>static VALUE
rb_str_each_char(VALUE str)
{
    RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size);
    return rb_str_enumerate_chars(str, 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-each_codepoint" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            each_codepoint {|integer| block }    &rarr; str
          </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>Passes the <a href="Integer.html"><code>Integer</code></a> ordinal of each character in <em>str</em>, also known as a <em>codepoint</em> when applied to Unicode strings to the given block.  For encodings other than UTF-8/UTF-16(BE|LE)/UTF-32(BE|LE), values are directly derived from the binary representation of each character.</p>

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

<pre class="ruby"><span class="ruby-string">&quot;hello\u0639&quot;</span>.<span class="ruby-identifier">each_codepoint</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-identifier">c</span>, <span class="ruby-string">&#39; &#39;</span> }
</pre>

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

<pre>104 101 108 108 111 1593</pre>
          
          

          
          <div class="method-source-code" id="each_codepoint-source">
            <pre>static VALUE
rb_str_each_codepoint(VALUE str)
{
    RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size);
    return rb_str_enumerate_codepoints(str, 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Passes each grapheme cluster in <em>str</em> to the given block, or returns an enumerator if no block is given. Unlike <a href="String.html#method-i-each_char"><code>String#each_char</code></a>, this enumerates by grapheme clusters defined by Unicode Standard Annex #29 <a href="http://unicode.org/reports/tr29">unicode.org/reports/tr29</a>/</p>

<pre class="ruby"><span class="ruby-string">&quot;a\u0300&quot;</span>.<span class="ruby-identifier">each_char</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment">#=&gt; 2</span>
<span class="ruby-string">&quot;a\u0300&quot;</span>.<span class="ruby-identifier">each_grapheme_cluster</span>.<span class="ruby-identifier">to_a</span>.<span class="ruby-identifier">size</span> <span class="ruby-comment">#=&gt; 1</span>
</pre>
          
          

          
          <div class="method-source-code" id="each_grapheme_cluster-source">
            <pre>static VALUE
rb_str_each_grapheme_cluster(VALUE str)
{
    RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_grapheme_cluster_size);
    return rb_str_enumerate_grapheme_clusters(str, 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-each_line" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            each_line(separator=$/, chomp: false) {|substr| block } &rarr; str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            each_line(separator=$/, chomp: false)                   &rarr; an_enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Splits <em>str</em> using the supplied parameter as the record separator (<code>$/</code> by default), passing each substring in turn to the supplied block.  If a zero-length record separator is supplied, the string is split into paragraphs delimited by multiple successive newlines.</p>

<p>If <code>chomp</code> is <code>true</code>, <code>separator</code> will be removed from the end of each line.</p>

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

<pre class="ruby"><span class="ruby-string">&quot;hello\nworld&quot;</span>.<span class="ruby-identifier">each_line</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>}
<span class="ruby-comment"># prints:</span>
<span class="ruby-comment">#   &quot;hello\n&quot;</span>
<span class="ruby-comment">#   &quot;world&quot;</span>

<span class="ruby-string">&quot;hello\nworld&quot;</span>.<span class="ruby-identifier">each_line</span>(<span class="ruby-string">&#39;l&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>}
<span class="ruby-comment"># prints:</span>
<span class="ruby-comment">#   &quot;hel&quot;</span>
<span class="ruby-comment">#   &quot;l&quot;</span>
<span class="ruby-comment">#   &quot;o\nworl&quot;</span>
<span class="ruby-comment">#   &quot;d&quot;</span>

<span class="ruby-string">&quot;hello\n\n\nworld&quot;</span>.<span class="ruby-identifier">each_line</span>(<span class="ruby-string">&#39;&#39;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>}
<span class="ruby-comment"># prints</span>
<span class="ruby-comment">#   &quot;hello\n\n&quot;</span>
<span class="ruby-comment">#   &quot;world&quot;</span>

<span class="ruby-string">&quot;hello\nworld&quot;</span>.<span class="ruby-identifier">each_line</span>(<span class="ruby-value">chomp:</span> <span class="ruby-keyword">true</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>}
<span class="ruby-comment"># prints:</span>
<span class="ruby-comment">#   &quot;hello&quot;</span>
<span class="ruby-comment">#   &quot;world&quot;</span>

<span class="ruby-string">&quot;hello\nworld&quot;</span>.<span class="ruby-identifier">each_line</span>(<span class="ruby-string">&#39;l&#39;</span>, <span class="ruby-value">chomp:</span> <span class="ruby-keyword">true</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>}
<span class="ruby-comment"># prints:</span>
<span class="ruby-comment">#   &quot;he&quot;</span>
<span class="ruby-comment">#   &quot;&quot;</span>
<span class="ruby-comment">#   &quot;o\nwor&quot;</span>
<span class="ruby-comment">#   &quot;d&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="each_line-source">
            <pre>static VALUE
rb_str_each_line(int argc, VALUE *argv, VALUE str)
{
    RETURN_SIZED_ENUMERATOR(str, argc, argv, 0);
    return rb_str_enumerate_lines(argc, argv, str, 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-empty-3F" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            empty?   &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 <em>str</em> has a length of zero.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">empty?</span>   <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot; &quot;</span>.<span class="ruby-identifier">empty?</span>       <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot;&quot;</span>.<span class="ruby-identifier">empty?</span>        <span class="ruby-comment">#=&gt; true</span>
</pre>
          
          

          
          <div class="method-source-code" id="empty-3F-source">
            <pre>static VALUE
rb_str_empty(VALUE str)
{
    if (RSTRING_LEN(str) == 0)
        return Qtrue;
    return Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-encode" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            encode(encoding [, options] )   &rarr; str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            encode(dst_encoding, src_encoding [, options] )   &rarr; str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            encode([options])   &rarr; str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>The first form returns a copy of <code>str</code> transcoded to encoding <code>encoding</code>. The second form returns a copy of <code>str</code> transcoded from src_encoding to dst_encoding. The last form returns a copy of <code>str</code> transcoded to <code>Encoding.default_internal</code>.</p>

<p>By default, the first and second form raise <a href="Encoding/UndefinedConversionError.html"><code>Encoding::UndefinedConversionError</code></a> for characters that are undefined in the destination encoding, and <a href="Encoding/InvalidByteSequenceError.html"><code>Encoding::InvalidByteSequenceError</code></a> for invalid byte sequences in the source encoding. The last form by default does not raise exceptions but uses replacement strings.</p>

<p>The <code>options</code> <a href="Hash.html"><code>Hash</code></a> gives details for conversion and can have the following keys:</p>
<dl class="rdoc-list note-list"><dt>:invalid 
<dd>
<p>If the value is <code>:replace</code>, <a href="String.html#method-i-encode"><code>encode</code></a> replaces invalid byte sequences in <code>str</code> with the replacement character.  The default is to raise the <a href="Encoding/InvalidByteSequenceError.html"><code>Encoding::InvalidByteSequenceError</code></a> exception</p>
</dd><dt>:undef 
<dd>
<p>If the value is <code>:replace</code>, <a href="String.html#method-i-encode"><code>encode</code></a> replaces characters which are undefined in the destination encoding with the replacement character. The default is to raise the <a href="Encoding/UndefinedConversionError.html"><code>Encoding::UndefinedConversionError</code></a>.</p>
</dd><dt>:replace 
<dd>
<p>Sets the replacement string to the given value. The default replacement string is “uFFFD” for Unicode encoding forms, and “?” otherwise.</p>
</dd><dt>:fallback 
<dd>
<p>Sets the replacement string by the given object for undefined character.  The object should be a <a href="Hash.html"><code>Hash</code></a>, a <a href="Proc.html"><code>Proc</code></a>, a <a href="Method.html"><code>Method</code></a>, or an object which has [] method. Its key is an undefined character encoded in the source encoding of current transcoder. Its value can be any encoding until it can be converted into the destination encoding of the transcoder.</p>
</dd><dt>:xml 
<dd>
<p>The value must be <code>:text</code> or <code>:attr</code>. If the value is <code>:text</code> <a href="String.html#method-i-encode"><code>encode</code></a> replaces undefined characters with their (upper-case hexadecimal) numeric character references. &#39;&amp;&#39;, &#39;&lt;&#39;, and &#39;&gt;&#39; are converted to “&amp;amp;”, “&amp;lt;”, and “&amp;gt;”, respectively. If the value is <code>:attr</code>, <a href="String.html#method-i-encode"><code>encode</code></a> also quotes the replacement result (using &#39;“&#39;), and replaces &#39;”&#39; with “&amp;quot;”.</p>
</dd><dt>:cr_newline 
<dd>
<p>Replaces LF (“n”) with CR (“r”) if value is true.</p>
</dd><dt>:crlf_newline 
<dd>
<p>Replaces LF (“n”) with CRLF (“rn”) if value is true.</p>
</dd><dt>:universal_newline 
<dd>
<p>Replaces CRLF (“rn”) and CR (“r”) with LF (“n”) if value is true.</p>
</dd></dl>
          
          

          
          <div class="method-source-code" id="encode-source">
            <pre>static VALUE
str_encode(int argc, VALUE *argv, VALUE str)
{
    VALUE newstr = str;
    int encidx = str_transcode(argc, argv, &amp;newstr);
    return encoded_dup(newstr, str, encidx);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-encode-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            encode!(encoding [, options] )   &rarr; str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            encode!(dst_encoding, src_encoding [, options] )   &rarr; str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>The first form transcodes the contents of <em>str</em> from str.encoding to <code>encoding</code>. The second form transcodes the contents of <em>str</em> from src_encoding to dst_encoding. The options <a href="Hash.html"><code>Hash</code></a> gives details for conversion. See <a href="String.html#method-i-encode"><code>String#encode</code></a> for details. Returns the string even if no changes were made.</p>
          
          

          
          <div class="method-source-code" id="encode-21-source">
            <pre>static VALUE
str_encode_bang(int argc, VALUE *argv, VALUE str)
{
    VALUE newstr;
    int encidx;

    rb_check_frozen(str);

    newstr = str;
    encidx = str_transcode(argc, argv, &amp;newstr);

    if (encidx &lt; 0) return str;
    if (newstr == str) {
        rb_enc_associate_index(str, encidx);
        return str;
    }
    rb_str_shared_replace(str, newstr);
    return str_encode_associate(str, encidx);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-encoding" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            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 obj.</p>
          
          

          
          <div class="method-source-code" id="encoding-source">
            <pre>VALUE
rb_obj_encoding(VALUE obj)
{
    int idx = rb_enc_get_index(obj);
    if (idx &lt; 0) {
	rb_raise(rb_eTypeError, &quot;unknown encoding&quot;);
    }
    return rb_enc_from_encoding_index(idx &amp; ENC_INDEX_MASK);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-end_with-3F" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            end_with?([suffixes]+)   &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>str</code> ends with one of the <code>suffixes</code> given.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">end_with?</span>(<span class="ruby-string">&quot;ello&quot;</span>)               <span class="ruby-comment">#=&gt; true</span>

<span class="ruby-comment"># returns true if one of the +suffixes+ matches.</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">end_with?</span>(<span class="ruby-string">&quot;heaven&quot;</span>, <span class="ruby-string">&quot;ello&quot;</span>)     <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">end_with?</span>(<span class="ruby-string">&quot;heaven&quot;</span>, <span class="ruby-string">&quot;paradise&quot;</span>) <span class="ruby-comment">#=&gt; false</span>
</pre>
          
          

          
          <div class="method-source-code" id="end_with-3F-source">
            <pre>static VALUE
rb_str_end_with(int argc, VALUE *argv, VALUE str)
{
    int i;
    char *p, *s, *e;
    rb_encoding *enc;

    for (i=0; i&lt;argc; i++) {
        VALUE tmp = argv[i];
        StringValue(tmp);
        enc = rb_enc_check(str, tmp);
        if (RSTRING_LEN(str) &lt; RSTRING_LEN(tmp)) continue;
        p = RSTRING_PTR(str);
        e = p + RSTRING_LEN(str);
        s = e - RSTRING_LEN(tmp);
        if (rb_enc_left_char_head(p, s, e, enc) != s)
            continue;
        if (memcmp(s, RSTRING_PTR(tmp), RSTRING_LEN(tmp)) == 0)
            return Qtrue;
    }
    return Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Two strings are equal if they have the same length and content.</p>
          
          

          
          <div class="method-source-code" id="eql-3F-source">
            <pre>MJIT_FUNC_EXPORTED VALUE
rb_str_eql(VALUE str1, VALUE str2)
{
    if (str1 == str2) return Qtrue;
    if (!RB_TYPE_P(str2, T_STRING)) return Qfalse;
    return rb_str_eql_internal(str1, str2);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Changes the encoding to <code>encoding</code> and returns self.</p>
          
          

          
          <div class="method-source-code" id="force_encoding-source">
            <pre>static VALUE
rb_str_force_encoding(VALUE str, VALUE enc)
{
    str_modifiable(str);
    rb_enc_associate(str, rb_to_encoding(enc));
    ENC_CODERANGE_CLEAR(str);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-freeze" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">freeze</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="freeze-source">
            <pre>VALUE
rb_str_freeze(VALUE str)
{
    if (OBJ_FROZEN(str)) return str;
    rb_str_resize(str, RSTRING_LEN(str));
    return rb_obj_freeze(str);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>returns the <em>index</em>th byte as an integer.</p>
          
          

          
          <div class="method-source-code" id="getbyte-source">
            <pre>static VALUE
rb_str_getbyte(VALUE str, VALUE index)
{
    long pos = NUM2LONG(index);

    if (pos &lt; 0)
        pos += RSTRING_LEN(str);
    if (pos &lt; 0 ||  RSTRING_LEN(str) &lt;= pos)
        return Qnil;

    return INT2FIX((unsigned char)RSTRING_PTR(str)[pos]);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns an array of grapheme clusters in <em>str</em>.  This is a shorthand for <code>str.each_grapheme_cluster.to_a</code>.</p>

<p>If a block is given, which is a deprecated form, works the same as <code>each_grapheme_cluster</code>.</p>
          
          

          
          <div class="method-source-code" id="grapheme_clusters-source">
            <pre>static VALUE
rb_str_grapheme_clusters(VALUE str)
{
    VALUE ary = WANTARRAY(&quot;grapheme_clusters&quot;, rb_str_strlen(str));
    return rb_str_enumerate_grapheme_clusters(str, ary);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-gsub" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            gsub(pattern, replacement)       &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gsub(pattern, hash)              &rarr; new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gsub(pattern) {|match| block }   &rarr; new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gsub(pattern)                    &rarr; enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns a copy of <em>str</em> with <em>all</em> occurrences of <em>pattern</em> substituted for the second argument. The <em>pattern</em> is typically a <a href="Regexp.html"><code>Regexp</code></a>; if given as a <a href="String.html"><code>String</code></a>, any regular expression metacharacters it contains will be interpreted literally, e.g. <code>\d</code> will match a backslash followed by &#39;d&#39;, instead of a digit.</p>

<p>If <code>replacement</code> is a <a href="String.html"><code>String</code></a> it will be substituted for the matched text. It may contain back-references to the pattern&#39;s capture groups of the form <code>\d</code>, where <em>d</em> is a group number, or <code>\k&lt;n&gt;</code>, where <em>n</em> is a group name. Similarly, <code>\&amp;</code>, <code>\&#39;</code>, <code>\`</code>, and <code>+</code> correspond to special variables, <code>$&amp;</code>, <code>$&#39;</code>, <code>$`</code>, and <code>$+</code>, respectively. (See <a href="regexp_rdoc.html">regexp.rdoc</a> for details.) <code>\0</code> is the same as <code>\&amp;</code>. <code>\\</code> is interpreted as an escape, i.e., a single backslash. Note that, within <code>replacement</code> the special match variables, such as <code>$&amp;</code>, will not refer to the current match.</p>

<p>If the second argument is a <a href="Hash.html"><code>Hash</code></a>, and the matched text is one of its keys, the corresponding value is the replacement string.</p>

<p>In the block form, the current match string is passed in as a parameter, and variables such as <code>$1</code>, <code>$2</code>, <code>$`</code>, <code>$&amp;</code>, and <code>$&#39;</code> will be set appropriately. (See <a href="regexp_rdoc.html">regexp.rdoc</a> for details.) The value returned by the block will be substituted for the match on each call.</p>

<p>When neither a block nor a second argument is supplied, an <a href="Enumerator.html"><code>Enumerator</code></a> is returned.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/[aeiou]/</span>, <span class="ruby-string">&#39;*&#39;</span>)                  <span class="ruby-comment">#=&gt; &quot;h*ll*&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/([aeiou])/</span>, <span class="ruby-string">&#39;&lt;\1&gt;&#39;</span>)             <span class="ruby-comment">#=&gt; &quot;h&lt;e&gt;ll&lt;o&gt;&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/./</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">ord</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-string">&#39; &#39;</span>}      <span class="ruby-comment">#=&gt; &quot;104 101 108 108 111 &quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/(?&lt;foo&gt;[aeiou])/</span>, <span class="ruby-string">&#39;{\k&lt;foo&gt;}&#39;</span>)  <span class="ruby-comment">#=&gt; &quot;h{e}ll{o}&quot;</span>
<span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/[eo]/</span>, <span class="ruby-string">&#39;e&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">3</span>, <span class="ruby-string">&#39;o&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;*&#39;</span>)    <span class="ruby-comment">#=&gt; &quot;h3ll*&quot;</span>
</pre>

<p>Note that a string literal consumes backslashes. (See <a href="syntax/literals_rdoc.html">syntax/literals.rdoc</a> for details on string literals.) Back-references are typically preceded by an additional backslash. For example, if you want to write a back-reference <code>\&amp;</code> in <code>replacement</code> with a double-quoted string literal, you need to write: <code>&quot;..\\&amp;..&quot;</code>. If you want to write a non-back-reference string <code>\&amp;</code> in <code>replacement</code>, you need first to escape the backslash to prevent this method from interpreting it as a back-reference, and then you need to escape the backslashes again to prevent a string literal from consuming them: <code>&quot;..\\\\&amp;..&quot;</code>. You may want to use the block form to avoid a lot of backslashes.</p>
          
          

          
          <div class="method-source-code" id="gsub-source">
            <pre>static VALUE
rb_str_gsub(int argc, VALUE *argv, VALUE str)
{
    return str_gsub(argc, argv, str, 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-gsub-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            gsub!(pattern, replacement)        &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gsub!(pattern, hash)               &rarr; str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gsub!(pattern) {|match| block }    &rarr; str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            gsub!(pattern)                     &rarr; an_enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Performs the substitutions of <a href="String.html#method-i-gsub"><code>String#gsub</code></a> in place, returning <em>str</em>, or <code>nil</code> if no substitutions were performed.  If no block and no <em>replacement</em> is given, an enumerator is returned instead.</p>
          
          

          
          <div class="method-source-code" id="gsub-21-source">
            <pre>static VALUE
rb_str_gsub_bang(int argc, VALUE *argv, VALUE str)
{
    str_modify_keep_cr(str);
    return str_gsub(argc, argv, str, 1);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a hash based on the string&#39;s length, content and encoding.</p>

<p>See also <a href="Object.html#method-i-hash"><code>Object#hash</code></a>.</p>
          
          

          
          <div class="method-source-code" id="hash-source">
            <pre>static VALUE
rb_str_hash_m(VALUE str)
{
    st_index_t hval = rb_str_hash(str);
    return ST2FIX(hval);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Treats leading characters from <em>str</em> as a string of hexadecimal digits (with an optional sign and an optional <code>0x</code>) and returns the corresponding number. Zero is returned on error.</p>

<pre class="ruby"><span class="ruby-string">&quot;0x0a&quot;</span>.<span class="ruby-identifier">hex</span>     <span class="ruby-comment">#=&gt; 10</span>
<span class="ruby-string">&quot;-1234&quot;</span>.<span class="ruby-identifier">hex</span>    <span class="ruby-comment">#=&gt; -4660</span>
<span class="ruby-string">&quot;0&quot;</span>.<span class="ruby-identifier">hex</span>        <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-string">&quot;wombat&quot;</span>.<span class="ruby-identifier">hex</span>   <span class="ruby-comment">#=&gt; 0</span>
</pre>
          
          

          
          <div class="method-source-code" id="hex-source">
            <pre>static VALUE
rb_str_hex(VALUE str)
{
    return rb_str_to_inum(str, 16, FALSE);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-include-3F" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            include? other_str   &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 <em>str</em> contains the given string or character.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">include?</span> <span class="ruby-string">&quot;lo&quot;</span>   <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">include?</span> <span class="ruby-string">&quot;ol&quot;</span>   <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">include?</span> <span class="ruby-value">?h</span>     <span class="ruby-comment">#=&gt; true</span>
</pre>
          
          

          
          <div class="method-source-code" id="include-3F-source">
            <pre>static VALUE
rb_str_include(VALUE str, VALUE arg)
{
    long i;

    StringValue(arg);
    i = rb_str_index(str, arg, 0);

    if (i == -1) return Qfalse;
    return Qtrue;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-index" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            index(substring [, offset])   &rarr; integer or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            index(regexp [, offset])      &rarr; integer or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the index of the first occurrence of the given <em>substring</em> or pattern (<em>regexp</em>) in <em>str</em>. Returns <code>nil</code> if not found. If the second parameter is present, it specifies the position in the string to begin the search.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">index</span>(<span class="ruby-string">&#39;e&#39;</span>)             <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">index</span>(<span class="ruby-string">&#39;lo&#39;</span>)            <span class="ruby-comment">#=&gt; 3</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">index</span>(<span class="ruby-string">&#39;a&#39;</span>)             <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">index</span>(<span class="ruby-value">?e</span>)              <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">index</span>(<span class="ruby-regexp">/[aeiou]/</span>, <span class="ruby-value">-3</span>)   <span class="ruby-comment">#=&gt; 4</span>
</pre>
          
          

          
          <div class="method-source-code" id="index-source">
            <pre>static VALUE
rb_str_index_m(int argc, VALUE *argv, VALUE str)
{
    VALUE sub;
    VALUE initpos;
    long pos;

    if (rb_scan_args(argc, argv, &quot;11&quot;, &amp;sub, &amp;initpos) == 2) {
        pos = NUM2LONG(initpos);
    }
    else {
        pos = 0;
    }
    if (pos &lt; 0) {
        pos += str_strlen(str, NULL);
        if (pos &lt; 0) {
            if (RB_TYPE_P(sub, T_REGEXP)) {
                rb_backref_set(Qnil);
            }
            return Qnil;
        }
    }

    if (SPECIAL_CONST_P(sub)) goto generic;
    switch (BUILTIN_TYPE(sub)) {
      case T_REGEXP:
        if (pos &gt; str_strlen(str, NULL))
            return Qnil;
        pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
                         rb_enc_check(str, sub), single_byte_optimizable(str));

        pos = rb_reg_search(sub, str, pos, 0);
        pos = rb_str_sublen(str, pos);
        break;

      generic:
      default: {
        VALUE tmp;

        tmp = rb_check_string_type(sub);
        if (NIL_P(tmp)) {
            rb_raise(rb_eTypeError, &quot;type mismatch: %s given&quot;,
                     rb_obj_classname(sub));
        }
        sub = tmp;
      }
        /* fall through */
      case T_STRING:
        pos = rb_str_index(str, sub, pos);
        pos = rb_str_sublen(str, pos);
        break;
    }

    if (pos == -1) return Qnil;
    return LONG2NUM(pos);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Replaces the contents of <em>str</em> with the corresponding values in <em>other_str</em>.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-string">&quot;hello&quot;</span>         <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">replace</span> <span class="ruby-string">&quot;world&quot;</span>   <span class="ruby-comment">#=&gt; &quot;world&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="initialize_copy-source">
            <pre>VALUE
rb_str_replace(VALUE str, VALUE str2)
{
    str_modifiable(str);
    if (str == str2) return str;

    StringValue(str2);
    str_discard(str);
    return str_replace(str, str2);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-insert" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            insert(index, other_str)   &rarr; str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Inserts <em>other_str</em> before the character at the given <em>index</em>, modifying <em>str</em>. Negative indices count from the end of the string, and insert <em>after</em> the given character. The intent is insert <em>aString</em> so that it starts at the given <em>index</em>.</p>

<pre class="ruby"><span class="ruby-string">&quot;abcd&quot;</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">0</span>, <span class="ruby-string">&#39;X&#39;</span>)    <span class="ruby-comment">#=&gt; &quot;Xabcd&quot;</span>
<span class="ruby-string">&quot;abcd&quot;</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">3</span>, <span class="ruby-string">&#39;X&#39;</span>)    <span class="ruby-comment">#=&gt; &quot;abcXd&quot;</span>
<span class="ruby-string">&quot;abcd&quot;</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">4</span>, <span class="ruby-string">&#39;X&#39;</span>)    <span class="ruby-comment">#=&gt; &quot;abcdX&quot;</span>
<span class="ruby-string">&quot;abcd&quot;</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">-3</span>, <span class="ruby-string">&#39;X&#39;</span>)   <span class="ruby-comment">#=&gt; &quot;abXcd&quot;</span>
<span class="ruby-string">&quot;abcd&quot;</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-value">-1</span>, <span class="ruby-string">&#39;X&#39;</span>)   <span class="ruby-comment">#=&gt; &quot;abcdX&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="insert-source">
            <pre>static VALUE
rb_str_insert(VALUE str, VALUE idx, VALUE str2)
{
    long pos = NUM2LONG(idx);

    if (pos == -1) {
        return rb_str_append(str, str2);
    }
    else if (pos &lt; 0) {
        pos++;
    }
    rb_str_splice(str, pos, 0, str2);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a printable version of <em>str</em>, surrounded by quote marks, with special characters escaped.</p>

<pre class="ruby"><span class="ruby-identifier">str</span> = <span class="ruby-string">&quot;hello&quot;</span>
<span class="ruby-identifier">str</span>[<span class="ruby-value">3</span>] = <span class="ruby-string">&quot;\b&quot;</span>
<span class="ruby-identifier">str</span>.<span class="ruby-identifier">inspect</span>       <span class="ruby-comment">#=&gt; &quot;\&quot;hel\\bo\&quot;&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="inspect-source">
            <pre>VALUE
rb_str_inspect(VALUE str)
{
    int encidx = ENCODING_GET(str);
    rb_encoding *enc = rb_enc_from_index(encidx), *actenc;
    const char *p, *pend, *prev;
    char buf[CHAR_ESC_LEN + 1];
    VALUE result = rb_str_buf_new(0);
    rb_encoding *resenc = rb_default_internal_encoding();
    int unicode_p = rb_enc_unicode_p(enc);
    int asciicompat = rb_enc_asciicompat(enc);

    if (resenc == NULL) resenc = rb_default_external_encoding();
    if (!rb_enc_asciicompat(resenc)) resenc = rb_usascii_encoding();
    rb_enc_associate(result, resenc);
    str_buf_cat2(result, &quot;\&quot;&quot;);

    p = RSTRING_PTR(str); pend = RSTRING_END(str);
    prev = p;
    actenc = get_actual_encoding(encidx, str);
    if (actenc != enc) {
        enc = actenc;
        if (unicode_p) unicode_p = rb_enc_unicode_p(enc);
    }
    while (p &lt; pend) {
        unsigned int c, cc;
        int n;

        n = rb_enc_precise_mbclen(p, pend, enc);
        if (!MBCLEN_CHARFOUND_P(n)) {
            if (p &gt; prev) str_buf_cat(result, prev, p - prev);
            n = rb_enc_mbminlen(enc);
            if (pend &lt; p + n)
                n = (int)(pend - p);
            while (n--) {
                snprintf(buf, CHAR_ESC_LEN, &quot;\\x%02X&quot;, *p &amp; 0377);
                str_buf_cat(result, buf, strlen(buf));
                prev = ++p;
            }
            continue;
        }
        n = MBCLEN_CHARFOUND_LEN(n);
        c = rb_enc_mbc_to_codepoint(p, pend, enc);
        p += n;
        if ((asciicompat || unicode_p) &amp;&amp;
          (c == &#39;&quot;&#39;|| c == &#39;\\&#39; ||
            (c == &#39;#&#39; &amp;&amp;
             p &lt; pend &amp;&amp;
             MBCLEN_CHARFOUND_P(rb_enc_precise_mbclen(p,pend,enc)) &amp;&amp;
             (cc = rb_enc_codepoint(p,pend,enc),
              (cc == &#39;$&#39; || cc == &#39;@&#39; || cc == &#39;{&#39;))))) {
            if (p - n &gt; prev) str_buf_cat(result, prev, p - n - prev);
            str_buf_cat2(result, &quot;\\&quot;);
            if (asciicompat || enc == resenc) {
                prev = p - n;
                continue;
            }
        }
        switch (c) {
          case &#39;\n&#39;: cc = &#39;n&#39;; break;
          case &#39;\r&#39;: cc = &#39;r&#39;; break;
          case &#39;\t&#39;: cc = &#39;t&#39;; break;
          case &#39;\f&#39;: cc = &#39;f&#39;; break;
          case &#39;\013&#39;: cc = &#39;v&#39;; break;
          case &#39;\010&#39;: cc = &#39;b&#39;; break;
          case &#39;\007&#39;: cc = &#39;a&#39;; break;
          case 033: cc = &#39;e&#39;; break;
          default: cc = 0; break;
        }
        if (cc) {
            if (p - n &gt; prev) str_buf_cat(result, prev, p - n - prev);
            buf[0] = &#39;\\&#39;;
            buf[1] = (char)cc;
            str_buf_cat(result, buf, 2);
            prev = p;
            continue;
        }
        if ((enc == resenc &amp;&amp; rb_enc_isprint(c, enc)) ||
            (asciicompat &amp;&amp; rb_enc_isascii(c, enc) &amp;&amp; ISPRINT(c))) {
            continue;
        }
        else {
            if (p - n &gt; prev) str_buf_cat(result, prev, p - n - prev);
            rb_str_buf_cat_escaped_char(result, c, unicode_p);
            prev = p;
            continue;
        }
    }
    if (p &gt; prev) str_buf_cat(result, prev, p - prev);
    str_buf_cat2(result, &quot;\&quot;&quot;);

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the <a href="Symbol.html"><code>Symbol</code></a> corresponding to <em>str</em>, creating the symbol if it did not previously exist. See <a href="Symbol.html#method-i-id2name"><code>Symbol#id2name</code></a>.</p>

<pre class="ruby"><span class="ruby-string">&quot;Koala&quot;</span>.<span class="ruby-identifier">intern</span>         <span class="ruby-comment">#=&gt; :Koala</span>
<span class="ruby-identifier">s</span> = <span class="ruby-string">&#39;cat&#39;</span>.<span class="ruby-identifier">to_sym</span>       <span class="ruby-comment">#=&gt; :cat</span>
<span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> <span class="ruby-value">:cat</span>              <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">s</span> = <span class="ruby-string">&#39;@cat&#39;</span>.<span class="ruby-identifier">to_sym</span>      <span class="ruby-comment">#=&gt; :@cat</span>
<span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> <span class="ruby-value">:@cat</span>             <span class="ruby-comment">#=&gt; true</span>
</pre>

<p>This can also be used to create symbols that cannot be represented using the <code>:xxx</code> notation.</p>

<pre class="ruby"><span class="ruby-string">&#39;cat and dog&#39;</span>.<span class="ruby-identifier">to_sym</span>   <span class="ruby-comment">#=&gt; :&quot;cat and dog&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="intern-source">
            <pre>VALUE
rb_str_intern(VALUE str)
{
#if USE_SYMBOL_GC
    rb_encoding *enc, *ascii;
    int type;
#else
    ID id;
#endif
    VALUE sym = lookup_str_sym(str);

    if (sym) {
	return sym;
    }

#if USE_SYMBOL_GC
    enc = rb_enc_get(str);
    ascii = rb_usascii_encoding();
    if (enc != ascii &amp;&amp; sym_check_asciionly(str)) {
	str = rb_str_dup(str);
	rb_enc_associate(str, ascii);
	OBJ_FREEZE(str);
	enc = ascii;
    }
    else {
        str = rb_str_dup(str);
        OBJ_FREEZE(str);
    }
    str = rb_fstring(str);
    type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
    if (type &lt; 0) type = ID_JUNK;
    return dsymbol_alloc(rb_cSymbol, str, enc, type);
#else
    id = intern_str(str, 0);
    return ID2SYM(id);
#endif
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns whether <code>self</code>&#39;s encoding is EUC-JP or not.</p>
          
          

          
          <div class="method-source-code" id="iseuc-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 264</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">iseuc</span>;    <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">iseuc</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns whether <code>self</code>&#39;s encoding is ISO-2022-JP or not.</p>
          
          

          
          <div class="method-source-code" id="isjis-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 276</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">isjis</span>;    <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">isjis</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns whether <code>self</code>&#39;s encoding is Shift_JIS or not.</p>
          
          

          
          <div class="method-source-code" id="issjis-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 270</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">issjis</span>;   <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">issjis</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns whether <code>self</code>&#39;s encoding is UTF-8 or not.</p>
          
          

          
          <div class="method-source-code" id="isutf8-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 282</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">isutf8</span>;   <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">isutf8</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-kconv" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            String#kconv(to_enc, from_enc)
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Convert <code>self</code> to <code>to_enc</code>. <code>to_enc</code> and <code>from_enc</code> are given as constants of <a href="Kconv.html"><code>Kconv</code></a> or <a href="Encoding.html"><code>Encoding</code></a> objects.</p>
          
          

          
          <div class="method-source-code" id="kconv-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 205</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">kconv</span>(<span class="ruby-identifier">to_enc</span>, <span class="ruby-identifier">from_enc</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">from_enc</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">encoding</span> <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">from_enc</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">encoding</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">Encoding</span>.<span class="ruby-identifier">list</span>[<span class="ruby-value">0</span>]
  <span class="ruby-constant">Kconv</span><span class="ruby-operator">::</span><span class="ruby-identifier">kconv</span>(<span class="ruby-keyword">self</span>, <span class="ruby-identifier">to_enc</span>, <span class="ruby-identifier">from_enc</span>)
<span class="ruby-keyword">end</span></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 character length of <em>str</em>.</p>
          
          

          
          <div class="method-source-code" id="length-source">
            <pre>VALUE
rb_str_length(VALUE str)
{
    return LONG2NUM(str_strlen(str, NULL));
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns an array of lines in <em>str</em> split using the supplied record separator (<code>$/</code> by default).  This is a shorthand for <code>str.each_line(separator, getline_args).to_a</code>.</p>

<p>If <code>chomp</code> is <code>true</code>, <code>separator</code> will be removed from the end of each line.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello\nworld\n&quot;</span>.<span class="ruby-identifier">lines</span>              <span class="ruby-comment">#=&gt; [&quot;hello\n&quot;, &quot;world\n&quot;]</span>
<span class="ruby-string">&quot;hello  world&quot;</span>.<span class="ruby-identifier">lines</span>(<span class="ruby-string">&#39; &#39;</span>)           <span class="ruby-comment">#=&gt; [&quot;hello &quot;, &quot; &quot;, &quot;world&quot;]</span>
<span class="ruby-string">&quot;hello\nworld\n&quot;</span>.<span class="ruby-identifier">lines</span>(<span class="ruby-value">chomp:</span> <span class="ruby-keyword">true</span>) <span class="ruby-comment">#=&gt; [&quot;hello&quot;, &quot;world&quot;]</span>
</pre>

<p>If a block is given, which is a deprecated form, works the same as <code>each_line</code>.</p>
          
          

          
          <div class="method-source-code" id="lines-source">
            <pre>static VALUE
rb_str_lines(int argc, VALUE *argv, VALUE str)
{
    VALUE ary = WANTARRAY(&quot;lines&quot;, 0);
    return rb_str_enumerate_lines(argc, argv, str, ary);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-ljust" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            ljust(integer, padstr=&#39; &#39;)   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>If <em>integer</em> is greater than the length of <em>str</em>, returns a new <a href="String.html"><code>String</code></a> of length <em>integer</em> with <em>str</em> left justified and padded with <em>padstr</em>; otherwise, returns <em>str</em>.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">ljust</span>(<span class="ruby-value">4</span>)            <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">ljust</span>(<span class="ruby-value">20</span>)           <span class="ruby-comment">#=&gt; &quot;hello               &quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">ljust</span>(<span class="ruby-value">20</span>, <span class="ruby-string">&#39;1234&#39;</span>)   <span class="ruby-comment">#=&gt; &quot;hello123412341234123&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="ljust-source">
            <pre>static VALUE
rb_str_ljust(int argc, VALUE *argv, VALUE str)
{
    return rb_str_justify(argc, argv, str, &#39;l&#39;);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of the receiver with leading whitespace removed. See also <a href="String.html#method-i-rstrip"><code>String#rstrip</code></a> and <a href="String.html#method-i-strip"><code>String#strip</code></a>.</p>

<p>Refer to <a href="String.html#method-i-strip"><code>String#strip</code></a> for the definition of whitespace.</p>

<pre class="ruby"><span class="ruby-string">&quot;  hello  &quot;</span>.<span class="ruby-identifier">lstrip</span>   <span class="ruby-comment">#=&gt; &quot;hello  &quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">lstrip</span>       <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="lstrip-source">
            <pre>static VALUE
rb_str_lstrip(VALUE str)
{
    char *start;
    long len, loffset;
    RSTRING_GETMEM(str, start, len);
    loffset = lstrip_offset(str, start, start+len, STR_ENC_GET(str));
    if (loffset &lt;= 0) return rb_str_dup(str);
    return rb_str_subseq(str, loffset, len - loffset);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Removes leading whitespace from the receiver. Returns the altered receiver, or <code>nil</code> if no change was made. See also <a href="String.html#method-i-rstrip-21"><code>String#rstrip!</code></a> and <a href="String.html#method-i-strip-21"><code>String#strip!</code></a>.</p>

<p>Refer to <a href="String.html#method-i-strip"><code>String#strip</code></a> for the definition of whitespace.</p>

<pre class="ruby"><span class="ruby-string">&quot;  hello  &quot;</span>.<span class="ruby-identifier">lstrip!</span>  <span class="ruby-comment">#=&gt; &quot;hello  &quot;</span>
<span class="ruby-string">&quot;hello  &quot;</span>.<span class="ruby-identifier">lstrip!</span>    <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">lstrip!</span>      <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="lstrip-21-source">
            <pre>static VALUE
rb_str_lstrip_bang(VALUE str)
{
    rb_encoding *enc;
    char *start, *s;
    long olen, loffset;

    str_modify_keep_cr(str);
    enc = STR_ENC_GET(str);
    RSTRING_GETMEM(str, start, olen);
    loffset = lstrip_offset(str, start, start+olen, enc);
    if (loffset &gt; 0) {
        long len = olen-loffset;
        s = start + loffset;
        memmove(start, s, len);
        STR_SET_LEN(str, len);
#if !SHARABLE_MIDDLE_SUBSTRING
        TERM_FILL(start+len, rb_enc_mbminlen(enc));
#endif
        return str;
    }
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-match" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            match(pattern)        &rarr; matchdata or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            match(pattern, pos)   &rarr; matchdata or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Converts <em>pattern</em> to a <a href="Regexp.html"><code>Regexp</code></a> (if it isn&#39;t already one), then invokes its <code>match</code> method on <em>str</em>.  If the second parameter is present, it specifies the position in the string to begin the search.</p>

<pre class="ruby"><span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">match</span>(<span class="ruby-string">&#39;(.)\1&#39;</span>)      <span class="ruby-comment">#=&gt; #&lt;MatchData &quot;ll&quot; 1:&quot;l&quot;&gt;</span>
<span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">match</span>(<span class="ruby-string">&#39;(.)\1&#39;</span>)[<span class="ruby-value">0</span>]   <span class="ruby-comment">#=&gt; &quot;ll&quot;</span>
<span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/(.)\1/</span>)[<span class="ruby-value">0</span>]   <span class="ruby-comment">#=&gt; &quot;ll&quot;</span>
<span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/(.)\1/</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-string">&#39;hello&#39;</span>.<span class="ruby-identifier">match</span>(<span class="ruby-string">&#39;xx&#39;</span>)         <span class="ruby-comment">#=&gt; nil</span>
</pre>

<p>If a block is given, invoke the block with <a href="MatchData.html"><code>MatchData</code></a> if match succeed, so that you can write</p>

<pre>str.match(pat) {|m| ...}</pre>

<p>instead of</p>

<pre>if m = str.match(pat)
  ...
end</pre>

<p>The return value is a value from block execution in this case.</p>
          
          

          
          <div class="method-source-code" id="match-source">
            <pre>static VALUE
rb_str_match_m(int argc, VALUE *argv, VALUE str)
{
    VALUE re, result;
    if (argc &lt; 1)
        rb_check_arity(argc, 1, 2);
    re = argv[0];
    argv[0] = str;
    result = rb_funcallv(get_pat(re), rb_intern(&quot;match&quot;), argc, argv);
    if (!NIL_P(result) &amp;&amp; rb_block_given_p()) {
        return rb_yield(result);
    }
    return result;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Converts <em>pattern</em> to a <code>Regexp</code> (if it isn&#39;t already one), then returns a <code>true</code> or <code>false</code> indicates whether the regexp is matched <em>str</em> or not without updating <code>$~</code> and other related variables.  If the second parameter is present, it specifies the position in the string to begin the search.</p>

<pre class="ruby"><span class="ruby-string">&quot;Ruby&quot;</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/R.../</span>)    <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;Ruby&quot;</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/R.../</span>, <span class="ruby-value">1</span>) <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot;Ruby&quot;</span>.<span class="ruby-identifier">match?</span>(<span class="ruby-regexp">/P.../</span>)    <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-node">$&amp;</span>                       <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="match-3F-source">
            <pre>static VALUE
rb_str_match_m_p(int argc, VALUE *argv, VALUE str)
{
    VALUE re;
    rb_check_arity(argc, 1, 2);
    re = get_pat(argv[0]);
    return rb_reg_match_p(re, str, argc &gt; 1 ? NUM2LONG(argv[1]) : 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the successor to <em>str</em>. The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing a letter results in another letter of the same case. Incrementing nonalphanumerics uses the underlying character set&#39;s collating sequence.</p>

<p>If the increment generates a “carry,&#39;&#39; the character to the left of it is incremented. This process repeats until there is no carry, adding an additional character if necessary.</p>

<pre class="ruby"><span class="ruby-string">&quot;abcd&quot;</span>.<span class="ruby-identifier">succ</span>        <span class="ruby-comment">#=&gt; &quot;abce&quot;</span>
<span class="ruby-string">&quot;THX1138&quot;</span>.<span class="ruby-identifier">succ</span>     <span class="ruby-comment">#=&gt; &quot;THX1139&quot;</span>
<span class="ruby-string">&quot;&lt;&lt;koala&gt;&gt;&quot;</span>.<span class="ruby-identifier">succ</span>   <span class="ruby-comment">#=&gt; &quot;&lt;&lt;koalb&gt;&gt;&quot;</span>
<span class="ruby-string">&quot;1999zzz&quot;</span>.<span class="ruby-identifier">succ</span>     <span class="ruby-comment">#=&gt; &quot;2000aaa&quot;</span>
<span class="ruby-string">&quot;ZZZ9999&quot;</span>.<span class="ruby-identifier">succ</span>     <span class="ruby-comment">#=&gt; &quot;AAAA0000&quot;</span>
<span class="ruby-string">&quot;***&quot;</span>.<span class="ruby-identifier">succ</span>         <span class="ruby-comment">#=&gt; &quot;**+&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="next-source">
            <pre>VALUE
rb_str_succ(VALUE orig)
{
    VALUE str;
    str = rb_str_new_with_class(orig, RSTRING_PTR(orig), RSTRING_LEN(orig));
    rb_enc_cr_str_copy_for_substr(str, orig);
    return str_succ(str);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Equivalent to <a href="String.html#method-i-succ"><code>String#succ</code></a>, but modifies the receiver in place.</p>
          
          

          
          <div class="method-source-code" id="next-21-source">
            <pre>static VALUE
rb_str_succ_bang(VALUE str)
{
    rb_str_modify(str);
    str_succ(str);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Treats leading characters of <em>str</em> as a string of octal digits (with an optional sign) and returns the corresponding number.  Returns 0 if the conversion fails.</p>

<pre class="ruby"><span class="ruby-string">&quot;123&quot;</span>.<span class="ruby-identifier">oct</span>       <span class="ruby-comment">#=&gt; 83</span>
<span class="ruby-string">&quot;-377&quot;</span>.<span class="ruby-identifier">oct</span>      <span class="ruby-comment">#=&gt; -255</span>
<span class="ruby-string">&quot;bad&quot;</span>.<span class="ruby-identifier">oct</span>       <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-string">&quot;0377bad&quot;</span>.<span class="ruby-identifier">oct</span>   <span class="ruby-comment">#=&gt; 255</span>
</pre>

<p>If <code>str</code> starts with <code>0</code>, radix indicators are honored. See Kernel#Integer.</p>
          
          

          
          <div class="method-source-code" id="oct-source">
            <pre>static VALUE
rb_str_oct(VALUE str)
{
    return rb_str_to_inum(str, -8, FALSE);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the <a href="Integer.html"><code>Integer</code></a> ordinal of a one-character string.</p>

<pre class="ruby"><span class="ruby-string">&quot;a&quot;</span>.<span class="ruby-identifier">ord</span>         <span class="ruby-comment">#=&gt; 97</span>
</pre>
          
          

          
          <div class="method-source-code" id="ord-source">
            <pre>VALUE
rb_str_ord(VALUE s)
{
    unsigned int c;

    c = rb_enc_codepoint(RSTRING_PTR(s), RSTRING_END(s), STR_ENC_GET(s));
    return UINT2NUM(c);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-partition" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            partition(sep)              &rarr; [head, sep, tail]
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            partition(regexp)           &rarr; [head, match, tail]
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Searches <em>sep</em> or pattern (<em>regexp</em>) in the string and returns the part before it, the match, and the part after it. If it is not found, returns two empty strings and <em>str</em>.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">partition</span>(<span class="ruby-string">&quot;l&quot;</span>)         <span class="ruby-comment">#=&gt; [&quot;he&quot;, &quot;l&quot;, &quot;lo&quot;]</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">partition</span>(<span class="ruby-string">&quot;x&quot;</span>)         <span class="ruby-comment">#=&gt; [&quot;hello&quot;, &quot;&quot;, &quot;&quot;]</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">partition</span>(<span class="ruby-regexp">/.l/</span>)        <span class="ruby-comment">#=&gt; [&quot;h&quot;, &quot;el&quot;, &quot;lo&quot;]</span>
</pre>
          
          

          
          <div class="method-source-code" id="partition-source">
            <pre>static VALUE
rb_str_partition(VALUE str, VALUE sep)
{
    long pos;

    sep = get_pat_quoted(sep, 0);
    if (RB_TYPE_P(sep, T_REGEXP)) {
        pos = rb_reg_search(sep, str, 0, 0);
        if (pos &lt; 0) {
          failed:
            return rb_ary_new3(3, rb_str_dup(str), str_new_empty(str), str_new_empty(str));
        }
        sep = rb_str_subpat(str, sep, INT2FIX(0));
        if (pos == 0 &amp;&amp; RSTRING_LEN(sep) == 0) goto failed;
    }
    else {
        pos = rb_str_index(str, sep, 0);
        if (pos &lt; 0) goto failed;
    }
    return rb_ary_new3(3, rb_str_subseq(str, 0, pos),
                          sep,
                          rb_str_subseq(str, pos+RSTRING_LEN(sep),
                                             RSTRING_LEN(str)-pos-RSTRING_LEN(sep)));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-prepend" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            prepend(other_str1, other_str2, ...)  &rarr; str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Prepend—Prepend the given strings to <em>str</em>.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;!&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">prepend</span>(<span class="ruby-string">&quot;hello &quot;</span>, <span class="ruby-string">&quot;world&quot;</span>) <span class="ruby-comment">#=&gt; &quot;hello world!&quot;</span>
<span class="ruby-identifier">a</span>                            <span class="ruby-comment">#=&gt; &quot;hello world!&quot;</span>
</pre>

<p>See also <a href="String.html#method-i-concat"><code>String#concat</code></a>.</p>
          
          

          
          <div class="method-source-code" id="prepend-source">
            <pre>static VALUE
rb_str_prepend_multi(int argc, VALUE *argv, VALUE str)
{
    str_modifiable(str);

    if (argc == 1) {
        rb_str_update(str, 0L, 0L, argv[0]);
    }
    else if (argc &gt; 1) {
        int i;
        VALUE arg_str = rb_str_tmp_new(0);
        rb_enc_copy(arg_str, str);
        for (i = 0; i &lt; argc; i++) {
            rb_str_append(arg_str, argv[i]);
        }
        rb_str_update(str, 0L, 0L, arg_str);
    }

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Replaces the contents of <em>str</em> with the corresponding values in <em>other_str</em>.</p>

<pre class="ruby"><span class="ruby-identifier">s</span> = <span class="ruby-string">&quot;hello&quot;</span>         <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">replace</span> <span class="ruby-string">&quot;world&quot;</span>   <span class="ruby-comment">#=&gt; &quot;world&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="replace-source">
            <pre>VALUE
rb_str_replace(VALUE str, VALUE str2)
{
    str_modifiable(str);
    if (str == str2) return str;

    StringValue(str2);
    str_discard(str);
    return str_replace(str, str2);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a new string with the characters from <em>str</em> in reverse order.</p>

<pre class="ruby"><span class="ruby-string">&quot;stressed&quot;</span>.<span class="ruby-identifier">reverse</span>   <span class="ruby-comment">#=&gt; &quot;desserts&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="reverse-source">
            <pre>static VALUE
rb_str_reverse(VALUE str)
{
    rb_encoding *enc;
    VALUE rev;
    char *s, *e, *p;
    int cr;

    if (RSTRING_LEN(str) &lt;= 1) return rb_str_dup(str);
    enc = STR_ENC_GET(str);
    rev = rb_str_new_with_class(str, 0, RSTRING_LEN(str));
    s = RSTRING_PTR(str); e = RSTRING_END(str);
    p = RSTRING_END(rev);
    cr = ENC_CODERANGE(str);

    if (RSTRING_LEN(str) &gt; 1) {
        if (single_byte_optimizable(str)) {
            while (s &lt; e) {
                *--p = *s++;
            }
        }
        else if (cr == ENC_CODERANGE_VALID) {
            while (s &lt; e) {
                int clen = rb_enc_fast_mbclen(s, e, enc);

                p -= clen;
                memcpy(p, s, clen);
                s += clen;
            }
        }
        else {
            cr = rb_enc_asciicompat(enc) ?
                ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
            while (s &lt; e) {
                int clen = rb_enc_mbclen(s, e, enc);

                if (clen &gt; 1 || (*s &amp; 0x80)) cr = ENC_CODERANGE_UNKNOWN;
                p -= clen;
                memcpy(p, s, clen);
                s += clen;
            }
        }
    }
    STR_SET_LEN(rev, RSTRING_LEN(str));
    str_enc_copy(rev, str);
    ENC_CODERANGE_SET(rev, cr);

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Reverses <em>str</em> in place.</p>
          
          

          
          <div class="method-source-code" id="reverse-21-source">
            <pre>static VALUE
rb_str_reverse_bang(VALUE str)
{
    if (RSTRING_LEN(str) &gt; 1) {
        if (single_byte_optimizable(str)) {
            char *s, *e, c;

            str_modify_keep_cr(str);
            s = RSTRING_PTR(str);
            e = RSTRING_END(str) - 1;
            while (s &lt; e) {
                c = *s;
                *s++ = *e;
                *e-- = c;
            }
        }
        else {
            str_shared_replace(str, rb_str_reverse(str));
        }
    }
    else {
        str_modify_keep_cr(str);
    }
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-rindex" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            rindex(substring [, integer])   &rarr; integer or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            rindex(regexp [, integer])   &rarr; integer or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns the index of the last occurrence of the given <em>substring</em> or pattern (<em>regexp</em>) in <em>str</em>. Returns <code>nil</code> if not found. If the second parameter is present, it specifies the position in the string to end the search—characters beyond this point will not be considered.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rindex</span>(<span class="ruby-string">&#39;e&#39;</span>)             <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rindex</span>(<span class="ruby-string">&#39;l&#39;</span>)             <span class="ruby-comment">#=&gt; 3</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rindex</span>(<span class="ruby-string">&#39;a&#39;</span>)             <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rindex</span>(<span class="ruby-value">?e</span>)              <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rindex</span>(<span class="ruby-regexp">/[aeiou]/</span>, <span class="ruby-value">-2</span>)   <span class="ruby-comment">#=&gt; 1</span>
</pre>
          
          

          
          <div class="method-source-code" id="rindex-source">
            <pre>static VALUE
rb_str_rindex_m(int argc, VALUE *argv, VALUE str)
{
    VALUE sub;
    VALUE vpos;
    rb_encoding *enc = STR_ENC_GET(str);
    long pos, len = str_strlen(str, enc); /* str&#39;s enc */

    if (rb_scan_args(argc, argv, &quot;11&quot;, &amp;sub, &amp;vpos) == 2) {
        pos = NUM2LONG(vpos);
        if (pos &lt; 0) {
            pos += len;
            if (pos &lt; 0) {
                if (RB_TYPE_P(sub, T_REGEXP)) {
                    rb_backref_set(Qnil);
                }
                return Qnil;
            }
        }
        if (pos &gt; len) pos = len;
    }
    else {
        pos = len;
    }

    if (SPECIAL_CONST_P(sub)) goto generic;
    switch (BUILTIN_TYPE(sub)) {
      case T_REGEXP:
        /* enc = rb_get_check(str, sub); */
        pos = str_offset(RSTRING_PTR(str), RSTRING_END(str), pos,
                         enc, single_byte_optimizable(str));

        pos = rb_reg_search(sub, str, pos, 1);
        pos = rb_str_sublen(str, pos);
        if (pos &gt;= 0) return LONG2NUM(pos);
        break;

      generic:
      default: {
        VALUE tmp;

        tmp = rb_check_string_type(sub);
        if (NIL_P(tmp)) {
            rb_raise(rb_eTypeError, &quot;type mismatch: %s given&quot;,
                     rb_obj_classname(sub));
        }
        sub = tmp;
      }
        /* fall through */
      case T_STRING:
        pos = rb_str_rindex(str, sub, pos);
        if (pos &gt;= 0) return LONG2NUM(pos);
        break;
    }
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-rjust" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            rjust(integer, padstr=&#39; &#39;)   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>If <em>integer</em> is greater than the length of <em>str</em>, returns a new <a href="String.html"><code>String</code></a> of length <em>integer</em> with <em>str</em> right justified and padded with <em>padstr</em>; otherwise, returns <em>str</em>.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rjust</span>(<span class="ruby-value">4</span>)            <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rjust</span>(<span class="ruby-value">20</span>)           <span class="ruby-comment">#=&gt; &quot;               hello&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rjust</span>(<span class="ruby-value">20</span>, <span class="ruby-string">&#39;1234&#39;</span>)   <span class="ruby-comment">#=&gt; &quot;123412341234123hello&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="rjust-source">
            <pre>static VALUE
rb_str_rjust(int argc, VALUE *argv, VALUE str)
{
    return rb_str_justify(argc, argv, str, &#39;r&#39;);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-rpartition" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            rpartition(sep)             &rarr; [head, sep, tail]
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            rpartition(regexp)          &rarr; [head, match, tail]
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Searches <em>sep</em> or pattern (<em>regexp</em>) in the string from the end of the string, and returns the part before it, the match, and the part after it. If it is not found, returns two empty strings and <em>str</em>.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rpartition</span>(<span class="ruby-string">&quot;l&quot;</span>)         <span class="ruby-comment">#=&gt; [&quot;hel&quot;, &quot;l&quot;, &quot;o&quot;]</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rpartition</span>(<span class="ruby-string">&quot;x&quot;</span>)         <span class="ruby-comment">#=&gt; [&quot;&quot;, &quot;&quot;, &quot;hello&quot;]</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rpartition</span>(<span class="ruby-regexp">/.l/</span>)        <span class="ruby-comment">#=&gt; [&quot;he&quot;, &quot;ll&quot;, &quot;o&quot;]</span>
</pre>
          
          

          
          <div class="method-source-code" id="rpartition-source">
            <pre>static VALUE
rb_str_rpartition(VALUE str, VALUE sep)
{
    long pos = RSTRING_LEN(str);
    int regex = FALSE;

    if (RB_TYPE_P(sep, T_REGEXP)) {
        pos = rb_reg_search(sep, str, pos, 1);
        regex = TRUE;
    }
    else {
        VALUE tmp;

        tmp = rb_check_string_type(sep);
        if (NIL_P(tmp)) {
            rb_raise(rb_eTypeError, &quot;type mismatch: %s given&quot;,
                     rb_obj_classname(sep));
        }
        sep = tmp;
        pos = rb_str_sublen(str, pos);
        pos = rb_str_rindex(str, sep, pos);
    }
    if (pos &lt; 0) {
       return rb_ary_new3(3, str_new_empty(str), str_new_empty(str), rb_str_dup(str));
    }
    if (regex) {
        sep = rb_reg_nth_match(0, rb_backref_get());
    }
    else {
        pos = rb_str_offset(str, pos);
    }
    return rb_ary_new3(3, rb_str_subseq(str, 0, pos),
                          sep,
                          rb_str_subseq(str, pos+RSTRING_LEN(sep),
                                        RSTRING_LEN(str)-pos-RSTRING_LEN(sep)));
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of the receiver with trailing whitespace removed. See also <a href="String.html#method-i-lstrip"><code>String#lstrip</code></a> and <a href="String.html#method-i-strip"><code>String#strip</code></a>.</p>

<p>Refer to <a href="String.html#method-i-strip"><code>String#strip</code></a> for the definition of whitespace.</p>

<pre class="ruby"><span class="ruby-string">&quot;  hello  &quot;</span>.<span class="ruby-identifier">rstrip</span>   <span class="ruby-comment">#=&gt; &quot;  hello&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rstrip</span>       <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="rstrip-source">
            <pre>static VALUE
rb_str_rstrip(VALUE str)
{
    rb_encoding *enc;
    char *start;
    long olen, roffset;

    enc = STR_ENC_GET(str);
    RSTRING_GETMEM(str, start, olen);
    roffset = rstrip_offset(str, start, start+olen, enc);

    if (roffset &lt;= 0) return rb_str_dup(str);
    return rb_str_subseq(str, 0, olen-roffset);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Removes trailing whitespace from the receiver. Returns the altered receiver, or <code>nil</code> if no change was made. See also <a href="String.html#method-i-lstrip-21"><code>String#lstrip!</code></a> and <a href="String.html#method-i-strip-21"><code>String#strip!</code></a>.</p>

<p>Refer to <a href="String.html#method-i-strip"><code>String#strip</code></a> for the definition of whitespace.</p>

<pre class="ruby"><span class="ruby-string">&quot;  hello  &quot;</span>.<span class="ruby-identifier">rstrip!</span>  <span class="ruby-comment">#=&gt; &quot;  hello&quot;</span>
<span class="ruby-string">&quot;  hello&quot;</span>.<span class="ruby-identifier">rstrip!</span>    <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">rstrip!</span>      <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="rstrip-21-source">
            <pre>static VALUE
rb_str_rstrip_bang(VALUE str)
{
    rb_encoding *enc;
    char *start;
    long olen, roffset;

    str_modify_keep_cr(str);
    enc = STR_ENC_GET(str);
    RSTRING_GETMEM(str, start, olen);
    roffset = rstrip_offset(str, start, start+olen, enc);
    if (roffset &gt; 0) {
        long len = olen - roffset;

        STR_SET_LEN(str, len);
#if !SHARABLE_MIDDLE_SUBSTRING
        TERM_FILL(start+len, rb_enc_mbminlen(enc));
#endif
        return str;
    }
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-scan" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            scan(pattern)                         &rarr; array
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            scan(pattern) {|match, ...| block }   &rarr; str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Both forms iterate through <em>str</em>, matching the pattern (which may be a <a href="Regexp.html"><code>Regexp</code></a> or a <a href="String.html"><code>String</code></a>). For each match, a result is generated and either added to the result array or passed to the block. If the pattern contains no groups, each individual result consists of the matched string, <code>$&amp;</code>.  If the pattern contains groups, each individual result is itself an array containing one entry per group.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;cruel world&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>)        <span class="ruby-comment">#=&gt; [&quot;cruel&quot;, &quot;world&quot;]</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/.../</span>)        <span class="ruby-comment">#=&gt; [&quot;cru&quot;, &quot;el &quot;, &quot;wor&quot;]</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(...)/</span>)      <span class="ruby-comment">#=&gt; [[&quot;cru&quot;], [&quot;el &quot;], [&quot;wor&quot;]]</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(..)(..)/</span>)   <span class="ruby-comment">#=&gt; [[&quot;cr&quot;, &quot;ue&quot;], [&quot;l &quot;, &quot;wo&quot;]]</span>
</pre>

<p>And the block form:</p>

<pre class="ruby"><span class="ruby-identifier">a</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/\w+/</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-node">&quot;&lt;&lt;#{w}&gt;&gt; &quot;</span> }
<span class="ruby-identifier">print</span> <span class="ruby-string">&quot;\n&quot;</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">scan</span>(<span class="ruby-regexp">/(.)(.)/</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-identifier">y</span>, <span class="ruby-identifier">x</span> }
<span class="ruby-identifier">print</span> <span class="ruby-string">&quot;\n&quot;</span>
</pre>

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

<pre>&lt;&lt;cruel&gt;&gt; &lt;&lt;world&gt;&gt;
rceu lowlr</pre>
          
          

          
          <div class="method-source-code" id="scan-source">
            <pre>static VALUE
rb_str_scan(VALUE str, VALUE pat)
{
    VALUE result;
    long start = 0;
    long last = -1, prev = 0;
    char *p = RSTRING_PTR(str); long len = RSTRING_LEN(str);

    pat = get_pat_quoted(pat, 1);
    mustnot_broken(str);
    if (!rb_block_given_p()) {
        VALUE ary = rb_ary_new();

        while (!NIL_P(result = scan_once(str, pat, &amp;start, 0))) {
            last = prev;
            prev = start;
            rb_ary_push(ary, result);
        }
        if (last &gt;= 0) rb_pat_search(pat, str, last, 1);
        else rb_backref_set(Qnil);
        return ary;
    }

    while (!NIL_P(result = scan_once(str, pat, &amp;start, 1))) {
        last = prev;
        prev = start;
        rb_yield(result);
        str_mod_check(str, p, len);
    }
    if (last &gt;= 0) rb_pat_search(pat, str, last, 1);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-scrub" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            scrub &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            scrub(repl) &rarr; new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            scrub{|bytes|} &rarr; new_str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>If the string is invalid byte sequence then replace invalid bytes with given replacement character, else returns self. If block is given, replace invalid bytes with returned value of the block.</p>

<pre class="ruby"><span class="ruby-string">&quot;abc\u3042\x81&quot;</span>.<span class="ruby-identifier">scrub</span> <span class="ruby-comment">#=&gt; &quot;abc\u3042\uFFFD&quot;</span>
<span class="ruby-string">&quot;abc\u3042\x81&quot;</span>.<span class="ruby-identifier">scrub</span>(<span class="ruby-string">&quot;*&quot;</span>) <span class="ruby-comment">#=&gt; &quot;abc\u3042*&quot;</span>
<span class="ruby-string">&quot;abc\u3042\xE3\x80&quot;</span>.<span class="ruby-identifier">scrub</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">bytes</span><span class="ruby-operator">|</span> <span class="ruby-string">&#39;&lt;&#39;</span><span class="ruby-operator">+</span><span class="ruby-identifier">bytes</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;H*&#39;</span>)[<span class="ruby-value">0</span>]<span class="ruby-string">+&#39;&gt;&#39;</span> } <span class="ruby-comment">#=&gt; &quot;abc\u3042&lt;e380&gt;&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="scrub-source">
            <pre>static VALUE
str_scrub(int argc, VALUE *argv, VALUE str)
{
    VALUE repl = argc ? (rb_check_arity(argc, 0, 1), argv[0]) : Qnil;
    VALUE new = rb_str_scrub(str, repl);
    return NIL_P(new) ? rb_str_dup(str): new;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-scrub-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            scrub! &rarr; str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            scrub!(repl) &rarr; str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            scrub!{|bytes|} &rarr; str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>If the string is invalid byte sequence then replace invalid bytes with given replacement character, else returns self. If block is given, replace invalid bytes with returned value of the block.</p>

<pre class="ruby"><span class="ruby-string">&quot;abc\u3042\x81&quot;</span>.<span class="ruby-identifier">scrub!</span> <span class="ruby-comment">#=&gt; &quot;abc\u3042\uFFFD&quot;</span>
<span class="ruby-string">&quot;abc\u3042\x81&quot;</span>.<span class="ruby-identifier">scrub!</span>(<span class="ruby-string">&quot;*&quot;</span>) <span class="ruby-comment">#=&gt; &quot;abc\u3042*&quot;</span>
<span class="ruby-string">&quot;abc\u3042\xE3\x80&quot;</span>.<span class="ruby-identifier">scrub!</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">bytes</span><span class="ruby-operator">|</span> <span class="ruby-string">&#39;&lt;&#39;</span><span class="ruby-operator">+</span><span class="ruby-identifier">bytes</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;H*&#39;</span>)[<span class="ruby-value">0</span>]<span class="ruby-string">+&#39;&gt;&#39;</span> } <span class="ruby-comment">#=&gt; &quot;abc\u3042&lt;e380&gt;&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="scrub-21-source">
            <pre>static VALUE
str_scrub_bang(int argc, VALUE *argv, VALUE str)
{
    VALUE repl = argc ? (rb_check_arity(argc, 0, 1), argv[0]) : Qnil;
    VALUE new = rb_str_scrub(str, repl);
    if (!NIL_P(new)) rb_str_replace(str, new);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>modifies the <em>index</em>th byte as <em>integer</em>.</p>
          
          

          
          <div class="method-source-code" id="setbyte-source">
            <pre>static VALUE
rb_str_setbyte(VALUE str, VALUE index, VALUE value)
{
    long pos = NUM2LONG(index);
    long len = RSTRING_LEN(str);
    char *head, *left = 0;
    unsigned char *ptr;
    rb_encoding *enc;
    int cr = ENC_CODERANGE_UNKNOWN, width, nlen;

    if (pos &lt; -len || len &lt;= pos)
        rb_raise(rb_eIndexError, &quot;index %ld out of string&quot;, pos);
    if (pos &lt; 0)
        pos += len;

    VALUE v = rb_to_int(value);
    VALUE w = rb_int_and(v, INT2FIX(0xff));
    unsigned char byte = NUM2INT(w) &amp; 0xFF;

    if (!str_independent(str))
        str_make_independent(str);
    enc = STR_ENC_GET(str);
    head = RSTRING_PTR(str);
    ptr = (unsigned char *)&amp;head[pos];
    if (!STR_EMBED_P(str)) {
        cr = ENC_CODERANGE(str);
        switch (cr) {
          case ENC_CODERANGE_7BIT:
            left = (char *)ptr;
            *ptr = byte;
            if (ISASCII(byte)) goto end;
            nlen = rb_enc_precise_mbclen(left, head+len, enc);
            if (!MBCLEN_CHARFOUND_P(nlen))
                ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);
            else
                ENC_CODERANGE_SET(str, ENC_CODERANGE_VALID);
            goto end;
          case ENC_CODERANGE_VALID:
            left = rb_enc_left_char_head(head, ptr, head+len, enc);
            width = rb_enc_precise_mbclen(left, head+len, enc);
            *ptr = byte;
            nlen = rb_enc_precise_mbclen(left, head+len, enc);
            if (!MBCLEN_CHARFOUND_P(nlen))
                ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);
            else if (MBCLEN_CHARFOUND_LEN(nlen) != width || ISASCII(byte))
                ENC_CODERANGE_CLEAR(str);
            goto end;
        }
    }
    ENC_CODERANGE_CLEAR(str);
    *ptr = byte;

  end:
    return value;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Escapes <code>str</code> so that it can be safely used in a Bourne shell command line.</p>

<p>See <a href="Shellwords.html#method-c-shellescape"><code>Shellwords.shellescape</code></a> for details.</p>
          
          

          
          <div class="method-source-code" id="shellescape-source">
            <pre><span class="ruby-comment"># File lib/shellwords.rb, line 215</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">shellescape</span>
  <span class="ruby-constant">Shellwords</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-keyword">self</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Splits <code>str</code> into an array of tokens in the same way the UNIX Bourne shell does.</p>

<p>See <a href="Shellwords.html#method-c-shellsplit"><code>Shellwords.shellsplit</code></a> for details.</p>
          
          

          
          <div class="method-source-code" id="shellsplit-source">
            <pre><span class="ruby-comment"># File lib/shellwords.rb, line 204</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">shellsplit</span>
  <span class="ruby-constant">Shellwords</span>.<span class="ruby-identifier">split</span>(<span class="ruby-keyword">self</span>)
<span class="ruby-keyword">end</span></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 character length of <em>str</em>.</p>
          
          

          
          <div class="method-source-code" id="size-source">
            <pre>VALUE
rb_str_length(VALUE str)
{
    return LONG2NUM(str_strlen(str, NULL));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-slice" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            slice(index)           &rarr; new_str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice(start, length)   &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice(range)           &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice(regexp)          &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice(regexp, capture) &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice(match_str)       &rarr; new_str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Element Reference — If passed a single <code>index</code>, returns a substring of one character at that index. If passed a <code>start</code> index and a <code>length</code>, returns a substring containing <code>length</code> characters starting at the <code>start</code> index. If passed a <code>range</code>, its beginning and end are interpreted as offsets delimiting the substring to be returned.</p>

<p>In these three cases, if an index is negative, it is counted from the end of the string.  For the <code>start</code> and <code>range</code> cases the starting index is just before a character and an index matching the string&#39;s size. Additionally, an empty string is returned when the starting index for a character range is at the end of the string.</p>

<p>Returns <code>nil</code> if the initial index falls outside the string or the length is negative.</p>

<p>If a <code>Regexp</code> is supplied, the matching portion of the string is returned.  If a <code>capture</code> follows the regular expression, which may be a capture group index or name, follows the regular expression that component of the <a href="MatchData.html"><code>MatchData</code></a> is returned instead.</p>

<p>If a <code>match_str</code> is given, that string is returned if it occurs in the string.</p>

<p>Returns <code>nil</code> if the regular expression does not match or the match string cannot be found.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-string">&quot;hello there&quot;</span>

<span class="ruby-identifier">a</span>[<span class="ruby-value">1</span>]                   <span class="ruby-comment">#=&gt; &quot;e&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">2</span>, <span class="ruby-value">3</span>]                <span class="ruby-comment">#=&gt; &quot;llo&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">2</span><span class="ruby-operator">..</span><span class="ruby-value">3</span>]                <span class="ruby-comment">#=&gt; &quot;ll&quot;</span>

<span class="ruby-identifier">a</span>[<span class="ruby-value">-3</span>, <span class="ruby-value">2</span>]               <span class="ruby-comment">#=&gt; &quot;er&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">7</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]               <span class="ruby-comment">#=&gt; &quot;her&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">-4</span><span class="ruby-operator">..</span><span class="ruby-value">-2</span>]              <span class="ruby-comment">#=&gt; &quot;her&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">-2</span><span class="ruby-operator">..</span><span class="ruby-value">-4</span>]              <span class="ruby-comment">#=&gt; &quot;&quot;</span>

<span class="ruby-identifier">a</span>[<span class="ruby-value">11</span>, <span class="ruby-value">0</span>]               <span class="ruby-comment">#=&gt; &quot;&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">11</span>]                  <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">12</span>, <span class="ruby-value">0</span>]               <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-identifier">a</span>[<span class="ruby-value">12</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]              <span class="ruby-comment">#=&gt; nil</span>

<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/[aeiou](.)\1/</span>]      <span class="ruby-comment">#=&gt; &quot;ell&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/[aeiou](.)\1/</span>, <span class="ruby-value">0</span>]   <span class="ruby-comment">#=&gt; &quot;ell&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/[aeiou](.)\1/</span>, <span class="ruby-value">1</span>]   <span class="ruby-comment">#=&gt; &quot;l&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/[aeiou](.)\1/</span>, <span class="ruby-value">2</span>]   <span class="ruby-comment">#=&gt; nil</span>

<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/(?&lt;vowel&gt;[aeiou])(?&lt;non_vowel&gt;[^aeiou])/</span>, <span class="ruby-string">&quot;non_vowel&quot;</span>] <span class="ruby-comment">#=&gt; &quot;l&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-regexp">/(?&lt;vowel&gt;[aeiou])(?&lt;non_vowel&gt;[^aeiou])/</span>, <span class="ruby-string">&quot;vowel&quot;</span>]     <span class="ruby-comment">#=&gt; &quot;e&quot;</span>

<span class="ruby-identifier">a</span>[<span class="ruby-string">&quot;lo&quot;</span>]                <span class="ruby-comment">#=&gt; &quot;lo&quot;</span>
<span class="ruby-identifier">a</span>[<span class="ruby-string">&quot;bye&quot;</span>]               <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="slice-source">
            <pre>static VALUE
rb_str_aref_m(int argc, VALUE *argv, VALUE str)
{
    if (argc == 2) {
        if (RB_TYPE_P(argv[0], T_REGEXP)) {
            return rb_str_subpat(str, argv[0], argv[1]);
        }
        else {
            long beg = NUM2LONG(argv[0]);
            long len = NUM2LONG(argv[1]);
            return rb_str_substr(str, beg, len);
        }
    }
    rb_check_arity(argc, 1, 2);
    return rb_str_aref(str, argv[0]);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-slice-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            slice!(integer)           &rarr; new_str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice!(integer, integer)   &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice!(range)            &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice!(regexp)           &rarr; new_str or nil
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            slice!(other_str)        &rarr; new_str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Deletes the specified portion from <em>str</em>, and returns the portion deleted.</p>

<pre class="ruby"><span class="ruby-identifier">string</span> = <span class="ruby-string">&quot;this is a string&quot;</span>
<span class="ruby-identifier">string</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">2</span>)        <span class="ruby-comment">#=&gt; &quot;i&quot;</span>
<span class="ruby-identifier">string</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">3</span><span class="ruby-operator">..</span><span class="ruby-value">6</span>)     <span class="ruby-comment">#=&gt; &quot; is &quot;</span>
<span class="ruby-identifier">string</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-regexp">/s.*t/</span>)   <span class="ruby-comment">#=&gt; &quot;sa st&quot;</span>
<span class="ruby-identifier">string</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-string">&quot;r&quot;</span>)      <span class="ruby-comment">#=&gt; &quot;r&quot;</span>
<span class="ruby-identifier">string</span>                  <span class="ruby-comment">#=&gt; &quot;thing&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="slice-21-source">
            <pre>static VALUE
rb_str_slice_bang(int argc, VALUE *argv, VALUE str)
{
    VALUE result;
    VALUE buf[3];
    int i;

    rb_check_arity(argc, 1, 2);
    for (i=0; i&lt;argc; i++) {
        buf[i] = argv[i];
    }
    str_modify_keep_cr(str);
    result = rb_str_aref_m(argc, buf, str);
    if (!NIL_P(result)) {
        buf[i] = rb_str_new(0,0);
        rb_str_aset_m(argc+1, buf, str);
    }
    return result;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-split" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            split(pattern=nil, [limit])                &rarr; an_array
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            split(pattern=nil, [limit]) {|sub| block } &rarr; str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Divides <em>str</em> into substrings based on a delimiter, returning an array of these substrings.</p>

<p>If <em>pattern</em> is a <a href="String.html"><code>String</code></a>, then its contents are used as the delimiter when splitting <em>str</em>. If <em>pattern</em> is a single space, <em>str</em> is split on whitespace, with leading and trailing whitespace and runs of contiguous whitespace characters ignored.</p>

<p>If <em>pattern</em> is a <a href="Regexp.html"><code>Regexp</code></a>, <em>str</em> is divided where the pattern matches. Whenever the pattern matches a zero-length string, <em>str</em> is split into individual characters. If <em>pattern</em> contains groups, the respective matches will be returned in the array as well.</p>

<p>If <em>pattern</em> is <code>nil</code>, the value of <code>$;</code> is used. If <code>$;</code> is <code>nil</code> (which is the default), <em>str</em> is split on whitespace as if &#39; &#39; were specified.</p>

<p>If the <em>limit</em> parameter is omitted, trailing null fields are suppressed. If <em>limit</em> is a positive number, at most that number of split substrings will be returned (captured groups will be returned as well, but are not counted towards the limit). If <em>limit</em> is <code>1</code>, the entire string is returned as the only entry in an array. If negative, there is no limit to the number of fields returned, and trailing null fields are not suppressed.</p>

<p>When the input <code>str</code> is empty an empty <a href="Array.html"><code>Array</code></a> is returned as the string is considered to have no fields to split.</p>

<pre class="ruby"><span class="ruby-string">&quot; now&#39;s  the time &quot;</span>.<span class="ruby-identifier">split</span>       <span class="ruby-comment">#=&gt; [&quot;now&#39;s&quot;, &quot;the&quot;, &quot;time&quot;]</span>
<span class="ruby-string">&quot; now&#39;s  the time &quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&#39; &#39;</span>)  <span class="ruby-comment">#=&gt; [&quot;now&#39;s&quot;, &quot;the&quot;, &quot;time&quot;]</span>
<span class="ruby-string">&quot; now&#39;s  the time&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">/ /</span>)   <span class="ruby-comment">#=&gt; [&quot;&quot;, &quot;now&#39;s&quot;, &quot;&quot;, &quot;the&quot;, &quot;time&quot;]</span>
<span class="ruby-string">&quot;1, 2.34,56, 7&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">%r{,\s*}</span>) <span class="ruby-comment">#=&gt; [&quot;1&quot;, &quot;2.34&quot;, &quot;56&quot;, &quot;7&quot;]</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">//</span>)               <span class="ruby-comment">#=&gt; [&quot;h&quot;, &quot;e&quot;, &quot;l&quot;, &quot;l&quot;, &quot;o&quot;]</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">//</span>, <span class="ruby-value">3</span>)            <span class="ruby-comment">#=&gt; [&quot;h&quot;, &quot;e&quot;, &quot;llo&quot;]</span>
<span class="ruby-string">&quot;hi mom&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">%r{\s*}</span>)         <span class="ruby-comment">#=&gt; [&quot;h&quot;, &quot;i&quot;, &quot;m&quot;, &quot;o&quot;, &quot;m&quot;]</span>

<span class="ruby-string">&quot;mellow yellow&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;ello&quot;</span>)   <span class="ruby-comment">#=&gt; [&quot;m&quot;, &quot;w y&quot;, &quot;w&quot;]</span>
<span class="ruby-string">&quot;1,2,,3,4,,&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&#39;,&#39;</span>)         <span class="ruby-comment">#=&gt; [&quot;1&quot;, &quot;2&quot;, &quot;&quot;, &quot;3&quot;, &quot;4&quot;]</span>
<span class="ruby-string">&quot;1,2,,3,4,,&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&#39;,&#39;</span>, <span class="ruby-value">4</span>)      <span class="ruby-comment">#=&gt; [&quot;1&quot;, &quot;2&quot;, &quot;&quot;, &quot;3,4,,&quot;]</span>
<span class="ruby-string">&quot;1,2,,3,4,,&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&#39;,&#39;</span>, <span class="ruby-value">-4</span>)     <span class="ruby-comment">#=&gt; [&quot;1&quot;, &quot;2&quot;, &quot;&quot;, &quot;3&quot;, &quot;4&quot;, &quot;&quot;, &quot;&quot;]</span>

<span class="ruby-string">&quot;1:2:3&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-regexp">/(:)()()/</span>, <span class="ruby-value">2</span>)     <span class="ruby-comment">#=&gt; [&quot;1&quot;, &quot;:&quot;, &quot;&quot;, &quot;&quot;, &quot;2:3&quot;]</span>

<span class="ruby-string">&quot;&quot;</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&#39;,&#39;</span>, <span class="ruby-value">-1</span>)               <span class="ruby-comment">#=&gt; []</span>
</pre>

<p>If a block is given, invoke the block with each split substring.</p>
          
          

          
          <div class="method-source-code" id="split-source">
            <pre>static VALUE
rb_str_split_m(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    VALUE spat;
    VALUE limit;
    enum {awk, string, regexp, chars} split_type;
    long beg, end, i = 0, empty_count = -1;
    int lim = 0;
    VALUE result, tmp;

    result = rb_block_given_p() ? Qfalse : Qnil;
    if (rb_scan_args(argc, argv, &quot;02&quot;, &amp;spat, &amp;limit) == 2) {
        lim = NUM2INT(limit);
        if (lim &lt;= 0) limit = Qnil;
        else if (lim == 1) {
            if (RSTRING_LEN(str) == 0)
                return result ? rb_ary_new2(0) : str;
            tmp = rb_str_dup(str);
            if (!result) {
                rb_yield(tmp);
                return str;
            }
            return rb_ary_new3(1, tmp);
        }
        i = 1;
    }
    if (NIL_P(limit) &amp;&amp; !lim) empty_count = 0;

    enc = STR_ENC_GET(str);
    split_type = regexp;
    if (!NIL_P(spat)) {
        spat = get_pat_quoted(spat, 0);
    }
    else if (NIL_P(spat = rb_fs)) {
        split_type = awk;
    }
    else if (!(spat = rb_fs_check(spat))) {
        rb_raise(rb_eTypeError, &quot;value of $; must be String or Regexp&quot;);
    }
    else {
        rb_warn(&quot;$; is set to non-nil value&quot;);
    }
    if (split_type != awk) {
        if (BUILTIN_TYPE(spat) == T_STRING) {
            rb_encoding *enc2 = STR_ENC_GET(spat);

            mustnot_broken(spat);
            split_type = string;
            if (RSTRING_LEN(spat) == 0) {
                /* Special case - split into chars */
                split_type = chars;
            }
            else if (rb_enc_asciicompat(enc2) == 1) {
                if (RSTRING_LEN(spat) == 1 &amp;&amp; RSTRING_PTR(spat)[0] == &#39; &#39;) {
                    split_type = awk;
                }
            }
            else {
                int l;
                if (rb_enc_ascget(RSTRING_PTR(spat), RSTRING_END(spat), &amp;l, enc2) == &#39; &#39; &amp;&amp;
                    RSTRING_LEN(spat) == l) {
                    split_type = awk;
                }
            }
        }
    }

#define SPLIT_STR(beg, len) (empty_count = split_string(result, str, beg, len, empty_count))

    if (result) result = rb_ary_new();
    beg = 0;
    char *ptr = RSTRING_PTR(str);
    char *eptr = RSTRING_END(str);
    if (split_type == awk) {
        char *bptr = ptr;
        int skip = 1;
        unsigned int c;

        end = beg;
        if (is_ascii_string(str)) {
            while (ptr &lt; eptr) {
                c = (unsigned char)*ptr++;
                if (skip) {
                    if (ascii_isspace(c)) {
                        beg = ptr - bptr;
                    }
                    else {
                        end = ptr - bptr;
                        skip = 0;
                        if (!NIL_P(limit) &amp;&amp; lim &lt;= i) break;
                    }
                }
                else if (ascii_isspace(c)) {
                    SPLIT_STR(beg, end-beg);
                    skip = 1;
                    beg = ptr - bptr;
                    if (!NIL_P(limit)) ++i;
                }
                else {
                    end = ptr - bptr;
                }
            }
        }
        else {
            while (ptr &lt; eptr) {
                int n;

                c = rb_enc_codepoint_len(ptr, eptr, &amp;n, enc);
                ptr += n;
                if (skip) {
                    if (rb_isspace(c)) {
                        beg = ptr - bptr;
                    }
                    else {
                        end = ptr - bptr;
                        skip = 0;
                        if (!NIL_P(limit) &amp;&amp; lim &lt;= i) break;
                    }
                }
                else if (rb_isspace(c)) {
                    SPLIT_STR(beg, end-beg);
                    skip = 1;
                    beg = ptr - bptr;
                    if (!NIL_P(limit)) ++i;
                }
                else {
                    end = ptr - bptr;
                }
            }
        }
    }
    else if (split_type == string) {
        char *str_start = ptr;
        char *substr_start = ptr;
        char *sptr = RSTRING_PTR(spat);
        long slen = RSTRING_LEN(spat);

        mustnot_broken(str);
        enc = rb_enc_check(str, spat);
        while (ptr &lt; eptr &amp;&amp;
               (end = rb_memsearch(sptr, slen, ptr, eptr - ptr, enc)) &gt;= 0) {
            /* Check we are at the start of a char */
            char *t = rb_enc_right_char_head(ptr, ptr + end, eptr, enc);
            if (t != ptr + end) {
                ptr = t;
                continue;
            }
            SPLIT_STR(substr_start - str_start, (ptr+end) - substr_start);
            ptr += end + slen;
            substr_start = ptr;
            if (!NIL_P(limit) &amp;&amp; lim &lt;= ++i) break;
        }
        beg = ptr - str_start;
    }
    else if (split_type == chars) {
        char *str_start = ptr;
        int n;

        mustnot_broken(str);
        enc = rb_enc_get(str);
        while (ptr &lt; eptr &amp;&amp;
               (n = rb_enc_precise_mbclen(ptr, eptr, enc)) &gt; 0) {
            SPLIT_STR(ptr - str_start, n);
            ptr += n;
            if (!NIL_P(limit) &amp;&amp; lim &lt;= ++i) break;
        }
        beg = ptr - str_start;
    }
    else {
        long len = RSTRING_LEN(str);
        long start = beg;
        long idx;
        int last_null = 0;
        struct re_registers *regs;
        VALUE match = 0;

        for (; (end = rb_reg_search(spat, str, start, 0)) &gt;= 0;
             (match ? (rb_match_unbusy(match), rb_backref_set(match)) : (void)0)) {
            match = rb_backref_get();
            if (!result) rb_match_busy(match);
            regs = RMATCH_REGS(match);
            if (start == end &amp;&amp; BEG(0) == END(0)) {
                if (!ptr) {
                    SPLIT_STR(0, 0);
                    break;
                }
                else if (last_null == 1) {
                    SPLIT_STR(beg, rb_enc_fast_mbclen(ptr+beg, eptr, enc));
                    beg = start;
                }
                else {
                    if (start == len)
                        start++;
                    else
                        start += rb_enc_fast_mbclen(ptr+start,eptr,enc);
                    last_null = 1;
                    continue;
                }
            }
            else {
                SPLIT_STR(beg, end-beg);
                beg = start = END(0);
            }
            last_null = 0;

            for (idx=1; idx &lt; regs-&gt;num_regs; idx++) {
                if (BEG(idx) == -1) continue;
                SPLIT_STR(BEG(idx), END(idx)-BEG(idx));
            }
            if (!NIL_P(limit) &amp;&amp; lim &lt;= ++i) break;
        }
        if (match) rb_match_unbusy(match);
    }
    if (RSTRING_LEN(str) &gt; 0 &amp;&amp; (!NIL_P(limit) || RSTRING_LEN(str) &gt; beg || lim &lt; 0)) {
        SPLIT_STR(beg, RSTRING_LEN(str)-beg);
    }

    return result ? result : str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-squeeze" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            squeeze([other_str]*)    &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Builds a set of characters from the <em>other_str</em> parameter(s) using the procedure described for <a href="String.html#method-i-count"><code>String#count</code></a>. Returns a new string where runs of the same character that occur in this set are replaced by a single character. If no arguments are given, all runs of identical characters are replaced by a single character.</p>

<pre class="ruby"><span class="ruby-string">&quot;yellow moon&quot;</span>.<span class="ruby-identifier">squeeze</span>                  <span class="ruby-comment">#=&gt; &quot;yelow mon&quot;</span>
<span class="ruby-string">&quot;  now   is  the&quot;</span>.<span class="ruby-identifier">squeeze</span>(<span class="ruby-string">&quot; &quot;</span>)         <span class="ruby-comment">#=&gt; &quot; now is the&quot;</span>
<span class="ruby-string">&quot;putters shoot balls&quot;</span>.<span class="ruby-identifier">squeeze</span>(<span class="ruby-string">&quot;m-z&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;puters shot balls&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="squeeze-source">
            <pre>static VALUE
rb_str_squeeze(int argc, VALUE *argv, VALUE str)
{
    str = rb_str_dup(str);
    rb_str_squeeze_bang(argc, argv, str);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-squeeze-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            squeeze!([other_str]*)   &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Squeezes <em>str</em> in place, returning either <em>str</em>, or <code>nil</code> if no changes were made.</p>
          
          

          
          <div class="method-source-code" id="squeeze-21-source">
            <pre>static VALUE
rb_str_squeeze_bang(int argc, VALUE *argv, VALUE str)
{
    char squeez[TR_TABLE_SIZE];
    rb_encoding *enc = 0;
    VALUE del = 0, nodel = 0;
    unsigned char *s, *send, *t;
    int i, modify = 0;
    int ascompat, singlebyte = single_byte_optimizable(str);
    unsigned int save;

    if (argc == 0) {
        enc = STR_ENC_GET(str);
    }
    else {
        for (i=0; i&lt;argc; i++) {
            VALUE s = argv[i];

            StringValue(s);
            enc = rb_enc_check(str, s);
            if (singlebyte &amp;&amp; !single_byte_optimizable(s))
                singlebyte = 0;
            tr_setup_table(s, squeez, i==0, &amp;del, &amp;nodel, enc);
        }
    }

    str_modify_keep_cr(str);
    s = t = (unsigned char *)RSTRING_PTR(str);
    if (!s || RSTRING_LEN(str) == 0) return Qnil;
    send = (unsigned char *)RSTRING_END(str);
    save = -1;
    ascompat = rb_enc_asciicompat(enc);

    if (singlebyte) {
        while (s &lt; send) {
            unsigned int c = *s++;
            if (c != save || (argc &gt; 0 &amp;&amp; !squeez[c])) {
                *t++ = save = c;
            }
        }
    }
    else {
        while (s &lt; send) {
            unsigned int c;
            int clen;

            if (ascompat &amp;&amp; (c = *s) &lt; 0x80) {
                if (c != save || (argc &gt; 0 &amp;&amp; !squeez[c])) {
                    *t++ = save = c;
                }
                s++;
            }
            else {
                c = rb_enc_codepoint_len((char *)s, (char *)send, &amp;clen, enc);

                if (c != save || (argc &gt; 0 &amp;&amp; !tr_find(c, squeez, del, nodel))) {
                    if (t != s) rb_enc_mbcput(c, t, enc);
                    save = c;
                    t += clen;
                }
                s += clen;
            }
        }
    }

    TERM_FILL((char *)t, TERM_LEN(str));
    if ((char *)t - RSTRING_PTR(str) != RSTRING_LEN(str)) {
        STR_SET_LEN(str, (char *)t - RSTRING_PTR(str));
        modify = 1;
    }

    if (modify) return str;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-start_with-3F" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            start_with?([prefixes]+)   &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>str</code> starts with one of the <code>prefixes</code> given. Each of the <code>prefixes</code> should be a <a href="String.html"><code>String</code></a> or a <a href="Regexp.html"><code>Regexp</code></a>.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">&quot;hell&quot;</span>)               <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-regexp">/H/i</span>)                 <span class="ruby-comment">#=&gt; true</span>

<span class="ruby-comment"># returns true if one of the prefixes matches.</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">&quot;heaven&quot;</span>, <span class="ruby-string">&quot;hell&quot;</span>)     <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">start_with?</span>(<span class="ruby-string">&quot;heaven&quot;</span>, <span class="ruby-string">&quot;paradise&quot;</span>) <span class="ruby-comment">#=&gt; false</span>
</pre>
          
          

          
          <div class="method-source-code" id="start_with-3F-source">
            <pre>static VALUE
rb_str_start_with(int argc, VALUE *argv, VALUE str)
{
    int i;

    for (i=0; i&lt;argc; i++) {
        VALUE tmp = argv[i];
        if (RB_TYPE_P(tmp, T_REGEXP)) {
            if (rb_reg_start_with_p(tmp, str))
                return Qtrue;
        }
        else {
            StringValue(tmp);
            rb_enc_check(str, tmp);
            if (RSTRING_LEN(str) &lt; RSTRING_LEN(tmp)) continue;
            if (memcmp(RSTRING_PTR(str), RSTRING_PTR(tmp), RSTRING_LEN(tmp)) == 0)
                return Qtrue;
        }
    }
    return Qfalse;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of the receiver with leading and trailing whitespace removed.</p>

<p>Whitespace is defined as any of the following characters: null, horizontal tab, line feed, vertical tab, form feed, carriage return, space.</p>

<pre class="ruby"><span class="ruby-string">&quot;    hello    &quot;</span>.<span class="ruby-identifier">strip</span>   <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;\tgoodbye\r\n&quot;</span>.<span class="ruby-identifier">strip</span>   <span class="ruby-comment">#=&gt; &quot;goodbye&quot;</span>
<span class="ruby-string">&quot;\x00\t\n\v\f\r &quot;</span>.<span class="ruby-identifier">strip</span> <span class="ruby-comment">#=&gt; &quot;&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">strip</span>           <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="strip-source">
            <pre>static VALUE
rb_str_strip(VALUE str)
{
    char *start;
    long olen, loffset, roffset;
    rb_encoding *enc = STR_ENC_GET(str);

    RSTRING_GETMEM(str, start, olen);
    loffset = lstrip_offset(str, start, start+olen, enc);
    roffset = rstrip_offset(str, start+loffset, start+olen, enc);

    if (loffset &lt;= 0 &amp;&amp; roffset &lt;= 0) return rb_str_dup(str);
    return rb_str_subseq(str, loffset, olen-loffset-roffset);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Removes leading and trailing whitespace from the receiver. Returns the altered receiver, or <code>nil</code> if there was no change.</p>

<p>Refer to <a href="String.html#method-i-strip"><code>String#strip</code></a> for the definition of whitespace.</p>

<pre class="ruby"><span class="ruby-string">&quot;  hello  &quot;</span>.<span class="ruby-identifier">strip!</span>  <span class="ruby-comment">#=&gt; &quot;hello&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">strip!</span>      <span class="ruby-comment">#=&gt; nil</span>
</pre>
          
          

          
          <div class="method-source-code" id="strip-21-source">
            <pre>static VALUE
rb_str_strip_bang(VALUE str)
{
    char *start;
    long olen, loffset, roffset;
    rb_encoding *enc;

    str_modify_keep_cr(str);
    enc = STR_ENC_GET(str);
    RSTRING_GETMEM(str, start, olen);
    loffset = lstrip_offset(str, start, start+olen, enc);
    roffset = rstrip_offset(str, start+loffset, start+olen, enc);

    if (loffset &gt; 0 || roffset &gt; 0) {
        long len = olen-roffset;
        if (loffset &gt; 0) {
            len -= loffset;
            memmove(start, start + loffset, len);
        }
        STR_SET_LEN(str, len);
#if !SHARABLE_MIDDLE_SUBSTRING
        TERM_FILL(start+len, rb_enc_mbminlen(enc));
#endif
        return str;
    }
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-sub" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            sub(pattern, replacement)         &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            sub(pattern, hash)                &rarr; new_str
          </span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            sub(pattern) {|match| block }     &rarr; new_str
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns a copy of <code>str</code> with the <em>first</em> occurrence of <code>pattern</code> replaced by the second argument. The <code>pattern</code> is typically a <a href="Regexp.html"><code>Regexp</code></a>; if given as a <a href="String.html"><code>String</code></a>, any regular expression metacharacters it contains will be interpreted literally, e.g. <code>\d</code> will match a backslash followed by &#39;d&#39;, instead of a digit.</p>

<p>If <code>replacement</code> is a <a href="String.html"><code>String</code></a> it will be substituted for the matched text. It may contain back-references to the pattern&#39;s capture groups of the form <code>\d</code>, where <em>d</em> is a group number, or <code>\k&lt;n&gt;</code>, where <em>n</em> is a group name. Similarly, <code>\&amp;</code>, <code>\&#39;</code>, <code>\`</code>, and <code>+</code> correspond to special variables, <code>$&amp;</code>, <code>$&#39;</code>, <code>$`</code>, and <code>$+</code>, respectively. (See <a href="regexp_rdoc.html">regexp.rdoc</a> for details.) <code>\0</code> is the same as <code>\&amp;</code>. <code>\\</code> is interpreted as an escape, i.e., a single backslash. Note that, within <code>replacement</code> the special match variables, such as <code>$&amp;</code>, will not refer to the current match.</p>

<p>If the second argument is a <a href="Hash.html"><code>Hash</code></a>, and the matched text is one of its keys, the corresponding value is the replacement string.</p>

<p>In the block form, the current match string is passed in as a parameter, and variables such as <code>$1</code>, <code>$2</code>, <code>$`</code>, <code>$&amp;</code>, and <code>$&#39;</code> will be set appropriately. (See <a href="regexp_rdoc.html">regexp.rdoc</a> for details.) The value returned by the block will be substituted for the match on each call.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/[aeiou]/</span>, <span class="ruby-string">&#39;*&#39;</span>)                  <span class="ruby-comment">#=&gt; &quot;h*llo&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/([aeiou])/</span>, <span class="ruby-string">&#39;&lt;\1&gt;&#39;</span>)             <span class="ruby-comment">#=&gt; &quot;h&lt;e&gt;llo&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/./</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">ord</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-string">&#39; &#39;</span> }     <span class="ruby-comment">#=&gt; &quot;104 ello&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/(?&lt;foo&gt;[aeiou])/</span>, <span class="ruby-string">&#39;*\k&lt;foo&gt;*&#39;</span>)  <span class="ruby-comment">#=&gt; &quot;h*e*llo&quot;</span>
<span class="ruby-string">&#39;Is SHELL your preferred shell?&#39;</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/[[:upper:]]{2,}/</span>, <span class="ruby-constant">ENV</span>)
 <span class="ruby-comment">#=&gt; &quot;Is /bin/bash your preferred shell?&quot;</span>
</pre>

<p>Note that a string literal consumes backslashes. (See <a href="syntax/literals_rdoc.html">syntax/literals.rdoc</a> for details about string literals.) Back-references are typically preceded by an additional backslash. For example, if you want to write a back-reference <code>\&amp;</code> in <code>replacement</code> with a double-quoted string literal, you need to write: <code>&quot;..\\&amp;..&quot;</code>. If you want to write a non-back-reference string <code>\&amp;</code> in <code>replacement</code>, you need first to escape the backslash to prevent this method from interpreting it as a back-reference, and then you need to escape the backslashes again to prevent a string literal from consuming them: <code>&quot;..\\\\&amp;..&quot;</code>. You may want to use the block form to avoid a lot of backslashes.</p>
          
          

          
          <div class="method-source-code" id="sub-source">
            <pre>static VALUE
rb_str_sub(int argc, VALUE *argv, VALUE str)
{
    str = rb_str_dup(str);
    rb_str_sub_bang(argc, argv, str);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-sub-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            sub!(pattern, replacement)          &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            sub!(pattern) {|match| block }      &rarr; str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Performs the same substitution as <a href="String.html#method-i-sub"><code>String#sub</code></a> in-place.</p>

<p>Returns <code>str</code> if a substitution was performed or <code>nil</code> if no substitution was performed.</p>
          
          

          
          <div class="method-source-code" id="sub-21-source">
            <pre>static VALUE
rb_str_sub_bang(int argc, VALUE *argv, VALUE str)
{
    VALUE pat, repl, hash = Qnil;
    int iter = 0;
    long plen;
    int min_arity = rb_block_given_p() ? 1 : 2;
    long beg;

    rb_check_arity(argc, min_arity, 2);
    if (argc == 1) {
        iter = 1;
    }
    else {
        repl = argv[1];
        hash = rb_check_hash_type(argv[1]);
        if (NIL_P(hash)) {
            StringValue(repl);
        }
    }

    pat = get_pat_quoted(argv[0], 1);

    str_modifiable(str);
    beg = rb_pat_search(pat, str, 0, 1);
    if (beg &gt;= 0) {
        rb_encoding *enc;
        int cr = ENC_CODERANGE(str);
        long beg0, end0;
        VALUE match, match0 = Qnil;
        struct re_registers *regs;
        char *p, *rp;
        long len, rlen;

        match = rb_backref_get();
        regs = RMATCH_REGS(match);
        if (RB_TYPE_P(pat, T_STRING)) {
            beg0 = beg;
            end0 = beg0 + RSTRING_LEN(pat);
            match0 = pat;
        }
        else {
            beg0 = BEG(0);
            end0 = END(0);
            if (iter) match0 = rb_reg_nth_match(0, match);
        }

        if (iter || !NIL_P(hash)) {
            p = RSTRING_PTR(str); len = RSTRING_LEN(str);

            if (iter) {
                repl = rb_obj_as_string(rb_yield(match0));
            }
            else {
                repl = rb_hash_aref(hash, rb_str_subseq(str, beg0, end0 - beg0));
                repl = rb_obj_as_string(repl);
            }
            str_mod_check(str, p, len);
            rb_check_frozen(str);
        }
        else {
            repl = rb_reg_regsub(repl, str, regs, RB_TYPE_P(pat, T_STRING) ? Qnil : pat);
        }

        enc = rb_enc_compatible(str, repl);
        if (!enc) {
            rb_encoding *str_enc = STR_ENC_GET(str);
            p = RSTRING_PTR(str); len = RSTRING_LEN(str);
            if (coderange_scan(p, beg0, str_enc) != ENC_CODERANGE_7BIT ||
                coderange_scan(p+end0, len-end0, str_enc) != ENC_CODERANGE_7BIT) {
                rb_raise(rb_eEncCompatError, &quot;incompatible character encodings: %s and %s&quot;,
                         rb_enc_name(str_enc),
                         rb_enc_name(STR_ENC_GET(repl)));
            }
            enc = STR_ENC_GET(repl);
        }
        rb_str_modify(str);
        rb_enc_associate(str, enc);
        if (ENC_CODERANGE_UNKNOWN &lt; cr &amp;&amp; cr &lt; ENC_CODERANGE_BROKEN) {
            int cr2 = ENC_CODERANGE(repl);
            if (cr2 == ENC_CODERANGE_BROKEN ||
                (cr == ENC_CODERANGE_VALID &amp;&amp; cr2 == ENC_CODERANGE_7BIT))
                cr = ENC_CODERANGE_UNKNOWN;
            else
                cr = cr2;
        }
        plen = end0 - beg0;
        rlen = RSTRING_LEN(repl);
        len = RSTRING_LEN(str);
        if (rlen &gt; plen) {
            RESIZE_CAPA(str, len + rlen - plen);
        }
        p = RSTRING_PTR(str);
        if (rlen != plen) {
            memmove(p + beg0 + rlen, p + beg0 + plen, len - beg0 - plen);
        }
        rp = RSTRING_PTR(repl);
        memmove(p + beg0, rp, rlen);
        len += rlen - plen;
        STR_SET_LEN(str, len);
        TERM_FILL(&amp;RSTRING_PTR(str)[len], TERM_LEN(str));
        ENC_CODERANGE_SET(str, cr);

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the successor to <em>str</em>. The successor is calculated by incrementing characters starting from the rightmost alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always results in another digit, and incrementing a letter results in another letter of the same case. Incrementing nonalphanumerics uses the underlying character set&#39;s collating sequence.</p>

<p>If the increment generates a “carry,&#39;&#39; the character to the left of it is incremented. This process repeats until there is no carry, adding an additional character if necessary.</p>

<pre class="ruby"><span class="ruby-string">&quot;abcd&quot;</span>.<span class="ruby-identifier">succ</span>        <span class="ruby-comment">#=&gt; &quot;abce&quot;</span>
<span class="ruby-string">&quot;THX1138&quot;</span>.<span class="ruby-identifier">succ</span>     <span class="ruby-comment">#=&gt; &quot;THX1139&quot;</span>
<span class="ruby-string">&quot;&lt;&lt;koala&gt;&gt;&quot;</span>.<span class="ruby-identifier">succ</span>   <span class="ruby-comment">#=&gt; &quot;&lt;&lt;koalb&gt;&gt;&quot;</span>
<span class="ruby-string">&quot;1999zzz&quot;</span>.<span class="ruby-identifier">succ</span>     <span class="ruby-comment">#=&gt; &quot;2000aaa&quot;</span>
<span class="ruby-string">&quot;ZZZ9999&quot;</span>.<span class="ruby-identifier">succ</span>     <span class="ruby-comment">#=&gt; &quot;AAAA0000&quot;</span>
<span class="ruby-string">&quot;***&quot;</span>.<span class="ruby-identifier">succ</span>         <span class="ruby-comment">#=&gt; &quot;**+&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="succ-source">
            <pre>VALUE
rb_str_succ(VALUE orig)
{
    VALUE str;
    str = rb_str_new_with_class(orig, RSTRING_PTR(orig), RSTRING_LEN(orig));
    rb_enc_cr_str_copy_for_substr(str, orig);
    return str_succ(str);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Equivalent to <a href="String.html#method-i-succ"><code>String#succ</code></a>, but modifies the receiver in place.</p>
          
          

          
          <div class="method-source-code" id="succ-21-source">
            <pre>static VALUE
rb_str_succ_bang(VALUE str)
{
    rb_str_modify(str);
    str_succ(str);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a basic <em>n</em>-bit checksum of the characters in <em>str</em>, where <em>n</em> is the optional <a href="Integer.html"><code>Integer</code></a> parameter, defaulting to 16. The result is simply the sum of the binary value of each byte in <em>str</em> modulo <code>2**n - 1</code>. This is not a particularly good checksum.</p>
          
          

          
          <div class="method-source-code" id="sum-source">
            <pre>static VALUE
rb_str_sum(int argc, VALUE *argv, VALUE str)
{
    int bits = 16;
    char *ptr, *p, *pend;
    long len;
    VALUE sum = INT2FIX(0);
    unsigned long sum0 = 0;

    if (rb_check_arity(argc, 0, 1) &amp;&amp; (bits = NUM2INT(argv[0])) &lt; 0) {
        bits = 0;
    }
    ptr = p = RSTRING_PTR(str);
    len = RSTRING_LEN(str);
    pend = p + len;

    while (p &lt; pend) {
        if (FIXNUM_MAX - UCHAR_MAX &lt; sum0) {
            sum = rb_funcall(sum, &#39;+&#39;, 1, LONG2FIX(sum0));
            str_mod_check(str, ptr, len);
            sum0 = 0;
        }
        sum0 += (unsigned char)*p;
        p++;
    }

    if (bits == 0) {
        if (sum0) {
            sum = rb_funcall(sum, &#39;+&#39;, 1, LONG2FIX(sum0));
        }
    }
    else {
        if (sum == INT2FIX(0)) {
            if (bits &lt; (int)sizeof(long)*CHAR_BIT) {
                sum0 &amp;= (((unsigned long)1)&lt;&lt;bits)-1;
            }
            sum = LONG2FIX(sum0);
        }
        else {
            VALUE mod;

            if (sum0) {
                sum = rb_funcall(sum, &#39;+&#39;, 1, LONG2FIX(sum0));
            }

            mod = rb_funcall(INT2FIX(1), idLTLT, 1, INT2FIX(bits));
            mod = rb_funcall(mod, &#39;-&#39;, 1, INT2FIX(1));
            sum = rb_funcall(sum, &#39;&amp;&#39;, 1, mod);
        }
    }
    return sum;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of <em>str</em> with uppercase alphabetic characters converted to lowercase and lowercase characters converted to uppercase.</p>

<p>See <a href="String.html#method-i-downcase"><code>String#downcase</code></a> for meaning of <code>options</code> and use with different encodings.</p>

<pre class="ruby"><span class="ruby-string">&quot;Hello&quot;</span>.<span class="ruby-identifier">swapcase</span>          <span class="ruby-comment">#=&gt; &quot;hELLO&quot;</span>
<span class="ruby-string">&quot;cYbEr_PuNk11&quot;</span>.<span class="ruby-identifier">swapcase</span>   <span class="ruby-comment">#=&gt; &quot;CyBeR_pUnK11&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="swapcase-source">
            <pre>static VALUE
rb_str_swapcase(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    OnigCaseFoldType flags = ONIGENC_CASE_UPCASE | ONIGENC_CASE_DOWNCASE;
    VALUE ret;

    flags = check_case_options(argc, argv, flags);
    enc = str_true_enc(str);
    if (RSTRING_LEN(str) == 0 || !RSTRING_PTR(str)) return str;
    if (flags&amp;ONIGENC_CASE_ASCII_ONLY) {
        ret = rb_str_new_with_class(str, 0, RSTRING_LEN(str));
        rb_str_ascii_casemap(str, ret, &amp;flags, enc);
    }
    else {
        ret = rb_str_casemap(str, &amp;flags, enc);
    }
    return ret;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-swapcase-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            swapcase!              &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            swapcase!([options])   &rarr; str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Equivalent to <a href="String.html#method-i-swapcase"><code>String#swapcase</code></a>, but modifies the receiver in place, returning <em>str</em>, or <code>nil</code> if no changes were made.</p>

<p>See <a href="String.html#method-i-downcase"><code>String#downcase</code></a> for meaning of <code>options</code> and use with different encodings.</p>
          
          

          
          <div class="method-source-code" id="swapcase-21-source">
            <pre>static VALUE
rb_str_swapcase_bang(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    OnigCaseFoldType flags = ONIGENC_CASE_UPCASE | ONIGENC_CASE_DOWNCASE;

    flags = check_case_options(argc, argv, flags);
    str_modify_keep_cr(str);
    enc = str_true_enc(str);
    if (flags&amp;ONIGENC_CASE_ASCII_ONLY)
        rb_str_ascii_casemap(str, str, &amp;flags, enc);
    else
        str_shared_replace(str, rb_str_casemap(str, &amp;flags, enc));

    if (ONIGENC_CASE_MODIFIED&amp;flags) return str;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a complex which denotes the string form.  The parser ignores leading whitespaces and trailing garbage.  Any digit sequences can be separated by an underscore.  Returns zero for null or garbage string.</p>

<pre class="ruby"><span class="ruby-string">&#39;9&#39;</span>.<span class="ruby-identifier">to_c</span>           <span class="ruby-comment">#=&gt; (9+0i)</span>
<span class="ruby-string">&#39;2.5&#39;</span>.<span class="ruby-identifier">to_c</span>         <span class="ruby-comment">#=&gt; (2.5+0i)</span>
<span class="ruby-string">&#39;2.5/1&#39;</span>.<span class="ruby-identifier">to_c</span>       <span class="ruby-comment">#=&gt; ((5/2)+0i)</span>
<span class="ruby-string">&#39;-3/2&#39;</span>.<span class="ruby-identifier">to_c</span>        <span class="ruby-comment">#=&gt; ((-3/2)+0i)</span>
<span class="ruby-string">&#39;-i&#39;</span>.<span class="ruby-identifier">to_c</span>          <span class="ruby-comment">#=&gt; (0-1i)</span>
<span class="ruby-string">&#39;45i&#39;</span>.<span class="ruby-identifier">to_c</span>         <span class="ruby-comment">#=&gt; (0+45i)</span>
<span class="ruby-string">&#39;3-4i&#39;</span>.<span class="ruby-identifier">to_c</span>        <span class="ruby-comment">#=&gt; (3-4i)</span>
<span class="ruby-string">&#39;-4e2-4e-2i&#39;</span>.<span class="ruby-identifier">to_c</span>  <span class="ruby-comment">#=&gt; (-400.0-0.04i)</span>
<span class="ruby-string">&#39;-0.0-0.0i&#39;</span>.<span class="ruby-identifier">to_c</span>   <span class="ruby-comment">#=&gt; (-0.0-0.0i)</span>
<span class="ruby-string">&#39;1/2+3/4i&#39;</span>.<span class="ruby-identifier">to_c</span>    <span class="ruby-comment">#=&gt; ((1/2)+(3/4)*i)</span>
<span class="ruby-string">&#39;ruby&#39;</span>.<span class="ruby-identifier">to_c</span>        <span class="ruby-comment">#=&gt; (0+0i)</span>
</pre>

<p>See <a href="Kernel.html"><code>Kernel</code></a>.Complex.</p>
          
          

          
          <div class="method-source-code" id="to_c-source">
            <pre>static VALUE
string_to_c(VALUE self)
{
    char *s;
    VALUE num;

    rb_must_asciicompat(self);

    s = RSTRING_PTR(self);

    if (s &amp;&amp; s[RSTRING_LEN(self)]) {
        rb_str_modify(self);
        s = RSTRING_PTR(self);
        s[RSTRING_LEN(self)] = &#39;\0&#39;;
    }

    if (!s)
        s = (char *)&quot;&quot;;

    (void)parse_comp(s, 0, &amp;num);

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

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the result of interpreting leading characters in <code>str</code> as a <a href="BigDecimal.html"><code>BigDecimal</code></a>.</p>

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

<span class="ruby-string">&quot;0.5&quot;</span>.<span class="ruby-identifier">to_d</span>             <span class="ruby-comment"># =&gt; 0.5e0</span>
<span class="ruby-string">&quot;123.45e1&quot;</span>.<span class="ruby-identifier">to_d</span>        <span class="ruby-comment"># =&gt; 0.12345e4</span>
<span class="ruby-string">&quot;45.67 degrees&quot;</span>.<span class="ruby-identifier">to_d</span>   <span class="ruby-comment"># =&gt; 0.4567e2</span>
</pre>

<p>See also <a href="BasicObject.html#method-c-new"><code>BigDecimal::new</code></a>.</p>
          
          

          
          <div class="method-source-code" id="to_d-source">
            <pre><span class="ruby-comment"># File ext/bigdecimal/lib/bigdecimal/util.rb, line 68</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_d</span>
  <span class="ruby-constant">BigDecimal</span>.<span class="ruby-identifier">interpret_loosely</span>(<span class="ruby-keyword">self</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the result of interpreting leading characters in <em>str</em> as a floating point number. Extraneous characters past the end of a valid number are ignored. If there is not a valid number at the start of <em>str</em>, <code>0.0</code> is returned. This method never raises an exception.</p>

<pre class="ruby"><span class="ruby-string">&quot;123.45e1&quot;</span>.<span class="ruby-identifier">to_f</span>        <span class="ruby-comment">#=&gt; 1234.5</span>
<span class="ruby-string">&quot;45.67 degrees&quot;</span>.<span class="ruby-identifier">to_f</span>   <span class="ruby-comment">#=&gt; 45.67</span>
<span class="ruby-string">&quot;thx1138&quot;</span>.<span class="ruby-identifier">to_f</span>         <span class="ruby-comment">#=&gt; 0.0</span>
</pre>
          
          

          
          <div class="method-source-code" id="to_f-source">
            <pre>static VALUE
rb_str_to_f(VALUE str)
{
    return DBL2NUM(rb_str_to_dbl(str, FALSE));
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the result of interpreting leading characters in <em>str</em> as an integer base <em>base</em> (between 2 and 36). Extraneous characters past the end of a valid number are ignored. If there is not a valid number at the start of <em>str</em>, <code>0</code> is returned. This method never raises an exception when <em>base</em> is valid.</p>

<pre class="ruby"><span class="ruby-string">&quot;12345&quot;</span>.<span class="ruby-identifier">to_i</span>             <span class="ruby-comment">#=&gt; 12345</span>
<span class="ruby-string">&quot;99 red balloons&quot;</span>.<span class="ruby-identifier">to_i</span>   <span class="ruby-comment">#=&gt; 99</span>
<span class="ruby-string">&quot;0a&quot;</span>.<span class="ruby-identifier">to_i</span>                <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-string">&quot;0a&quot;</span>.<span class="ruby-identifier">to_i</span>(<span class="ruby-value">16</span>)            <span class="ruby-comment">#=&gt; 10</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">to_i</span>             <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-string">&quot;1100101&quot;</span>.<span class="ruby-identifier">to_i</span>(<span class="ruby-value">2</span>)        <span class="ruby-comment">#=&gt; 101</span>
<span class="ruby-string">&quot;1100101&quot;</span>.<span class="ruby-identifier">to_i</span>(<span class="ruby-value">8</span>)        <span class="ruby-comment">#=&gt; 294977</span>
<span class="ruby-string">&quot;1100101&quot;</span>.<span class="ruby-identifier">to_i</span>(<span class="ruby-value">10</span>)       <span class="ruby-comment">#=&gt; 1100101</span>
<span class="ruby-string">&quot;1100101&quot;</span>.<span class="ruby-identifier">to_i</span>(<span class="ruby-value">16</span>)       <span class="ruby-comment">#=&gt; 17826049</span>
</pre>
          
          

          
          <div class="method-source-code" id="to_i-source">
            <pre>static VALUE
rb_str_to_i(int argc, VALUE *argv, VALUE str)
{
    int base = 10;

    if (rb_check_arity(argc, 0, 1) &amp;&amp; (base = NUM2INT(argv[0])) &lt; 0) {
        rb_raise(rb_eArgError, &quot;invalid radix %d&quot;, base);
    }
    return rb_str_to_inum(str, base, FALSE);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the result of interpreting leading characters in <code>str</code> as a rational.  Leading whitespace and extraneous characters past the end of a valid number are ignored. Digit sequences can be separated by an underscore. If there is not a valid number at the start of <code>str</code>, zero is returned.  This method never raises an exception.</p>

<pre class="ruby"><span class="ruby-string">&#39;  2  &#39;</span>.<span class="ruby-identifier">to_r</span>       <span class="ruby-comment">#=&gt; (2/1)</span>
<span class="ruby-string">&#39;300/2&#39;</span>.<span class="ruby-identifier">to_r</span>       <span class="ruby-comment">#=&gt; (150/1)</span>
<span class="ruby-string">&#39;-9.2&#39;</span>.<span class="ruby-identifier">to_r</span>        <span class="ruby-comment">#=&gt; (-46/5)</span>
<span class="ruby-string">&#39;-9.2e2&#39;</span>.<span class="ruby-identifier">to_r</span>      <span class="ruby-comment">#=&gt; (-920/1)</span>
<span class="ruby-string">&#39;1_234_567&#39;</span>.<span class="ruby-identifier">to_r</span>   <span class="ruby-comment">#=&gt; (1234567/1)</span>
<span class="ruby-string">&#39;21 June 09&#39;</span>.<span class="ruby-identifier">to_r</span>  <span class="ruby-comment">#=&gt; (21/1)</span>
<span class="ruby-string">&#39;21/06/09&#39;</span>.<span class="ruby-identifier">to_r</span>    <span class="ruby-comment">#=&gt; (7/2)</span>
<span class="ruby-string">&#39;BWV 1079&#39;</span>.<span class="ruby-identifier">to_r</span>    <span class="ruby-comment">#=&gt; (0/1)</span>
</pre>

<p>NOTE: “0.3”.to_r isn&#39;t the same as 0.3.to_r.  The former is equivalent to “3/10”.to_r, but the latter isn&#39;t so.</p>

<pre class="ruby"><span class="ruby-string">&quot;0.3&quot;</span>.<span class="ruby-identifier">to_r</span> <span class="ruby-operator">==</span> <span class="ruby-value">3</span><span class="ruby-operator">/</span><span class="ruby-value">10r</span>  <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-value">0.3</span>.<span class="ruby-identifier">to_r</span>   <span class="ruby-operator">==</span> <span class="ruby-value">3</span><span class="ruby-operator">/</span><span class="ruby-value">10r</span>  <span class="ruby-comment">#=&gt; false</span>
</pre>

<p>See also Kernel#Rational.</p>
          
          

          
          <div class="method-source-code" id="to_r-source">
            <pre>static VALUE
string_to_r(VALUE self)
{
    VALUE num;

    rb_must_asciicompat(self);

    num = parse_rat(RSTRING_PTR(self), RSTRING_END(self), 0, TRUE);

    if (RB_FLOAT_TYPE_P(num) &amp;&amp; !FLOAT_ZERO_P(num))
        rb_raise(rb_eFloatDomainError, &quot;Infinity&quot;);
    return num;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

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

<p>If called on a subclass of <a href="String.html"><code>String</code></a>, converts the receiver to a <a href="String.html"><code>String</code></a> object.</p>
          
          

          
          <div class="method-source-code" id="to_s-source">
            <pre>static VALUE
rb_str_to_s(VALUE str)
{
    if (rb_obj_class(str) != rb_cString) {
        return str_duplicate(rb_cString, str);
    }
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

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

<p>If called on a subclass of <a href="String.html"><code>String</code></a>, converts the receiver to a <a href="String.html"><code>String</code></a> object.</p>
          
          

          
          <div class="method-source-code" id="to_str-source">
            <pre>static VALUE
rb_str_to_s(VALUE str)
{
    if (rb_obj_class(str) != rb_cString) {
        return str_duplicate(rb_cString, str);
    }
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns the <a href="Symbol.html"><code>Symbol</code></a> corresponding to <em>str</em>, creating the symbol if it did not previously exist. See <a href="Symbol.html#method-i-id2name"><code>Symbol#id2name</code></a>.</p>

<pre class="ruby"><span class="ruby-string">&quot;Koala&quot;</span>.<span class="ruby-identifier">intern</span>         <span class="ruby-comment">#=&gt; :Koala</span>
<span class="ruby-identifier">s</span> = <span class="ruby-string">&#39;cat&#39;</span>.<span class="ruby-identifier">to_sym</span>       <span class="ruby-comment">#=&gt; :cat</span>
<span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> <span class="ruby-value">:cat</span>              <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-identifier">s</span> = <span class="ruby-string">&#39;@cat&#39;</span>.<span class="ruby-identifier">to_sym</span>      <span class="ruby-comment">#=&gt; :@cat</span>
<span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> <span class="ruby-value">:@cat</span>             <span class="ruby-comment">#=&gt; true</span>
</pre>

<p>This can also be used to create symbols that cannot be represented using the <code>:xxx</code> notation.</p>

<pre class="ruby"><span class="ruby-string">&#39;cat and dog&#39;</span>.<span class="ruby-identifier">to_sym</span>   <span class="ruby-comment">#=&gt; :&quot;cat and dog&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="to_sym-source">
            <pre>VALUE
rb_str_intern(VALUE str)
{
#if USE_SYMBOL_GC
    rb_encoding *enc, *ascii;
    int type;
#else
    ID id;
#endif
    VALUE sym = lookup_str_sym(str);

    if (sym) {
	return sym;
    }

#if USE_SYMBOL_GC
    enc = rb_enc_get(str);
    ascii = rb_usascii_encoding();
    if (enc != ascii &amp;&amp; sym_check_asciionly(str)) {
	str = rb_str_dup(str);
	rb_enc_associate(str, ascii);
	OBJ_FREEZE(str);
	enc = ascii;
    }
    else {
        str = rb_str_dup(str);
        OBJ_FREEZE(str);
    }
    str = rb_fstring(str);
    type = rb_str_symname_type(str, IDSET_ATTRSET_FOR_INTERN);
    if (type &lt; 0) type = ID_JUNK;
    return dsymbol_alloc(rb_cSymbol, str, enc, type);
#else
    id = intern_str(str, 0);
    return ID2SYM(id);
#endif
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Convert <code>self</code> to EUC-JP</p>
          
          

          
          <div class="method-source-code" id="toeuc-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 224</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">toeuc</span>; <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">toeuc</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Convert <code>self</code> to ISO-2022-JP</p>
          
          

          
          <div class="method-source-code" id="tojis-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 218</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">tojis</span>; <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">tojis</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Convert <code>self</code> to locale encoding</p>
          
          

          
          <div class="method-source-code" id="tolocale-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 254</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">tolocale</span>; <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">tolocale</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Convert <code>self</code> to Shift_JIS</p>
          
          

          
          <div class="method-source-code" id="tosjis-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 230</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">tosjis</span>; <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">tosjis</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Convert <code>self</code> to UTF-16</p>
          
          

          
          <div class="method-source-code" id="toutf16-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 242</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">toutf16</span>; <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">toutf16</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Convert <code>self</code> to UTF-32</p>
          
          

          
          <div class="method-source-code" id="toutf32-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 248</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">toutf32</span>; <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">toutf32</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Convert <code>self</code> to UTF-8</p>
          
          

          
          <div class="method-source-code" id="toutf8-source">
            <pre><span class="ruby-comment"># File ext/nkf/lib/kconv.rb, line 236</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">toutf8</span>; <span class="ruby-constant">Kconv</span>.<span class="ruby-identifier">toutf8</span>(<span class="ruby-keyword">self</span>) <span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-tr" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            tr(from_str, to_str)   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Returns a copy of <code>str</code> with the characters in <code>from_str</code> replaced by the corresponding characters in <code>to_str</code>.  If <code>to_str</code> is shorter than <code>from_str</code>, it is padded with its last character in order to maintain the correspondence.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&#39;el&#39;</span>, <span class="ruby-string">&#39;ip&#39;</span>)      <span class="ruby-comment">#=&gt; &quot;hippo&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&#39;aeiou&#39;</span>, <span class="ruby-string">&#39;*&#39;</span>)    <span class="ruby-comment">#=&gt; &quot;h*ll*&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&#39;aeiou&#39;</span>, <span class="ruby-string">&#39;AA*&#39;</span>)  <span class="ruby-comment">#=&gt; &quot;hAll*&quot;</span>
</pre>

<p>Both strings may use the <code>c1-c2</code> notation to denote ranges of characters, and <code>from_str</code> may start with a <code>^</code>, which denotes all characters except those listed.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&#39;a-y&#39;</span>, <span class="ruby-string">&#39;b-z&#39;</span>)    <span class="ruby-comment">#=&gt; &quot;ifmmp&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&#39;^aeiou&#39;</span>, <span class="ruby-string">&#39;*&#39;</span>)   <span class="ruby-comment">#=&gt; &quot;*e**o&quot;</span>
</pre>

<p>The backslash character <code>\</code> can be used to escape <code>^</code> or <code>-</code> and is otherwise ignored unless it appears at the end of a range or the end of the <code>from_str</code> or <code>to_str</code>:</p>

<pre class="ruby"><span class="ruby-string">&quot;hello^world&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&quot;\\^aeiou&quot;</span>, <span class="ruby-string">&quot;*&quot;</span>) <span class="ruby-comment">#=&gt; &quot;h*ll**w*rld&quot;</span>
<span class="ruby-string">&quot;hello-world&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&quot;a\\-eo&quot;</span>, <span class="ruby-string">&quot;*&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;h*ll**w*rld&quot;</span>

<span class="ruby-string">&quot;hello\r\nworld&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&quot;\r&quot;</span>, <span class="ruby-string">&quot;&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;hello\nworld&quot;</span>
<span class="ruby-string">&quot;hello\r\nworld&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&quot;\\r&quot;</span>, <span class="ruby-string">&quot;&quot;</span>)  <span class="ruby-comment">#=&gt; &quot;hello\r\nwold&quot;</span>
<span class="ruby-string">&quot;hello\r\nworld&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&quot;\\\r&quot;</span>, <span class="ruby-string">&quot;&quot;</span>) <span class="ruby-comment">#=&gt; &quot;hello\nworld&quot;</span>

<span class="ruby-string">&quot;X[&#39;\\b&#39;]&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&quot;X\\&quot;</span>, <span class="ruby-string">&quot;&quot;</span>)   <span class="ruby-comment">#=&gt; &quot;[&#39;b&#39;]&quot;</span>
<span class="ruby-string">&quot;X[&#39;\\b&#39;]&quot;</span>.<span class="ruby-identifier">tr</span>(<span class="ruby-string">&quot;X-\\]&quot;</span>, <span class="ruby-string">&quot;&quot;</span>) <span class="ruby-comment">#=&gt; &quot;&#39;b&#39;&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="tr-source">
            <pre>static VALUE
rb_str_tr(VALUE str, VALUE src, VALUE repl)
{
    str = rb_str_dup(str);
    tr_trans(str, src, repl, 0);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-tr-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            tr!(from_str, to_str)   &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Translates <em>str</em> in place, using the same rules as <a href="String.html#method-i-tr"><code>String#tr</code></a>. Returns <em>str</em>, or <code>nil</code> if no changes were made.</p>
          
          

          
          <div class="method-source-code" id="tr-21-source">
            <pre>static VALUE
rb_str_tr_bang(VALUE str, VALUE src, VALUE repl)
{
    return tr_trans(str, src, repl, 0);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-tr_s" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            tr_s(from_str, to_str)   &rarr; new_str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Processes a copy of <em>str</em> as described under <a href="String.html#method-i-tr"><code>String#tr</code></a>, then removes duplicate characters in regions that were affected by the translation.</p>

<pre class="ruby"><span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">tr_s</span>(<span class="ruby-string">&#39;l&#39;</span>, <span class="ruby-string">&#39;r&#39;</span>)     <span class="ruby-comment">#=&gt; &quot;hero&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">tr_s</span>(<span class="ruby-string">&#39;el&#39;</span>, <span class="ruby-string">&#39;*&#39;</span>)    <span class="ruby-comment">#=&gt; &quot;h*o&quot;</span>
<span class="ruby-string">&quot;hello&quot;</span>.<span class="ruby-identifier">tr_s</span>(<span class="ruby-string">&#39;el&#39;</span>, <span class="ruby-string">&#39;hx&#39;</span>)   <span class="ruby-comment">#=&gt; &quot;hhxo&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="tr_s-source">
            <pre>static VALUE
rb_str_tr_s(VALUE str, VALUE src, VALUE repl)
{
    str = rb_str_dup(str);
    tr_trans(str, src, repl, 1);
    return str;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-tr_s-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            tr_s!(from_str, to_str)   &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Performs <a href="String.html#method-i-tr_s"><code>String#tr_s</code></a> processing on <em>str</em> in place, returning <em>str</em>, or <code>nil</code> if no changes were made.</p>
          
          

          
          <div class="method-source-code" id="tr_s-21-source">
            <pre>static VALUE
rb_str_tr_s_bang(VALUE str, VALUE src, VALUE repl)
{
    return tr_trans(str, src, repl, 1);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns an unescaped version of the string. This does the inverse of <a href="String.html#method-i-dump"><code>String#dump</code></a>.</p>

<pre class="ruby"><span class="ruby-string">&quot;\&quot;hello \\n &#39;&#39;\&quot;&quot;</span>.<span class="ruby-identifier">undump</span> <span class="ruby-comment">#=&gt; &quot;hello \n &#39;&#39;&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="undump-source">
            <pre>static VALUE
str_undump(VALUE str)
{
    const char *s = RSTRING_PTR(str);
    const char *s_end = RSTRING_END(str);
    rb_encoding *enc = rb_enc_get(str);
    VALUE undumped = rb_enc_str_new(s, 0L, enc);
    bool utf8 = false;
    bool binary = false;
    int w;

    rb_must_asciicompat(str);
    if (rb_str_is_ascii_only_p(str) == Qfalse) {
        rb_raise(rb_eRuntimeError, &quot;non-ASCII character detected&quot;);
    }
    if (!str_null_check(str, &amp;w)) {
       rb_raise(rb_eRuntimeError, &quot;string contains null byte&quot;);
    }
    if (RSTRING_LEN(str) &lt; 2) goto invalid_format;
    if (*s != &#39;&quot;&#39;) goto invalid_format;

    /* strip &#39;&quot;&#39; at the start */
    s++;

    for (;;) {
        if (s &gt;= s_end) {
            rb_raise(rb_eRuntimeError, &quot;unterminated dumped string&quot;);
        }

        if (*s == &#39;&quot;&#39;) {
            /* epilogue */
            s++;
            if (s == s_end) {
                /* ascii compatible dumped string */
                break;
            }
            else {
                static const char force_encoding_suffix[] = &quot;.force_encoding(\&quot;&quot;; /* &quot;\&quot;)&quot; */
                static const char dup_suffix[] = &quot;.dup&quot;;
                const char *encname;
                int encidx;
                ptrdiff_t size;

                /* check separately for strings dumped by older versions */
                size = sizeof(dup_suffix) - 1;
                if (s_end - s &gt; size &amp;&amp; memcmp(s, dup_suffix, size) == 0) s += size;

                size = sizeof(force_encoding_suffix) - 1;
                if (s_end - s &lt;= size) goto invalid_format;
                if (memcmp(s, force_encoding_suffix, size) != 0) goto invalid_format;
                s += size;

                if (utf8) {
                    rb_raise(rb_eRuntimeError, &quot;dumped string contained Unicode escape but used force_encoding&quot;);
                }

                encname = s;
                s = memchr(s, &#39;&quot;&#39;, s_end-s);
                size = s - encname;
                if (!s) goto invalid_format;
                if (s_end - s != 2) goto invalid_format;
                if (s[0] != &#39;&quot;&#39; || s[1] != &#39;)&#39;) goto invalid_format;

                encidx = rb_enc_find_index2(encname, (long)size);
                if (encidx &lt; 0) {
                    rb_raise(rb_eRuntimeError, &quot;dumped string has unknown encoding name&quot;);
                }
                rb_enc_associate_index(undumped, encidx);
            }
            break;
        }

        if (*s == &#39;\\&#39;) {
            s++;
            if (s &gt;= s_end) {
                rb_raise(rb_eRuntimeError, &quot;invalid escape&quot;);
            }
            undump_after_backslash(undumped, &amp;s, s_end, &amp;enc, &amp;utf8, &amp;binary);
        }
        else {
            rb_str_cat(undumped, s++, 1);
        }
    }

    return undumped;
invalid_format:
    rb_raise(rb_eRuntimeError, &quot;invalid dumped string; not wrapped with &#39;\&quot;&#39; nor &#39;\&quot;...\&quot;.force_encoding(\&quot;...\&quot;)&#39; form&quot;);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-unicode_normalize" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            unicode_normalize(form=:nfc)
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Unicode Normalization—Returns a normalized form of <code>str</code>, using Unicode normalizations NFC, NFD, NFKC, or NFKD. The normalization form used is determined by <code>form</code>, which can be any of the four values <code>:nfc</code>, <code>:nfd</code>, <code>:nfkc</code>, or <code>:nfkd</code>. The default is <code>:nfc</code>.</p>

<p>If the string is not in a Unicode <a href="Encoding.html"><code>Encoding</code></a>, then an <a href="Exception.html"><code>Exception</code></a> is raised. In this context, &#39;Unicode Encoding&#39; means any of UTF-8, UTF-16BE/LE, and UTF-32BE/LE, as well as GB18030, UCS_2BE, and UCS_4BE. Anything other than UTF-8 is implemented by converting to UTF-8, which makes it slower than UTF-8.</p>

<pre class="ruby"><span class="ruby-string">&quot;a\u0300&quot;</span>.<span class="ruby-identifier">unicode_normalize</span>        <span class="ruby-comment">#=&gt; &quot;\u00E0&quot;</span>
<span class="ruby-string">&quot;a\u0300&quot;</span>.<span class="ruby-identifier">unicode_normalize</span>(<span class="ruby-value">:nfc</span>)  <span class="ruby-comment">#=&gt; &quot;\u00E0&quot;</span>
<span class="ruby-string">&quot;\u00E0&quot;</span>.<span class="ruby-identifier">unicode_normalize</span>(<span class="ruby-value">:nfd</span>)   <span class="ruby-comment">#=&gt; &quot;a\u0300&quot;</span>
<span class="ruby-string">&quot;\xE0&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&#39;ISO-8859-1&#39;</span>).<span class="ruby-identifier">unicode_normalize</span>(<span class="ruby-value">:nfd</span>)
                                   <span class="ruby-comment">#=&gt; Encoding::CompatibilityError raised</span>
</pre>
          
          

          
          <div class="method-source-code" id="unicode_normalize-source">
            <pre>static VALUE
rb_str_unicode_normalize(int argc, VALUE *argv, VALUE str)
{
    return unicode_normalize_common(argc, argv, str, id_normalize);
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-unicode_normalize-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            unicode_normalize!(form=:nfc)
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Destructive version of <a href="String.html#method-i-unicode_normalize"><code>String#unicode_normalize</code></a>, doing Unicode normalization in place.</p>
          
          

          
          <div class="method-source-code" id="unicode_normalize-21-source">
            <pre>static VALUE
rb_str_unicode_normalize_bang(int argc, VALUE *argv, VALUE str)
{
    return rb_str_replace(str, unicode_normalize_common(argc, argv, str, id_normalize));
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-unicode_normalized-3F" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            unicode_normalized?(form=:nfc)
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Checks whether <code>str</code> is in Unicode normalization form <code>form</code>, which can be any of the four values <code>:nfc</code>, <code>:nfd</code>, <code>:nfkc</code>, or <code>:nfkd</code>. The default is <code>:nfc</code>.</p>

<p>If the string is not in a Unicode <a href="Encoding.html"><code>Encoding</code></a>, then an <a href="Exception.html"><code>Exception</code></a> is raised. For details, see <a href="String.html#method-i-unicode_normalize"><code>String#unicode_normalize</code></a>.</p>

<pre class="ruby"><span class="ruby-string">&quot;a\u0300&quot;</span>.<span class="ruby-identifier">unicode_normalized?</span>        <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot;a\u0300&quot;</span>.<span class="ruby-identifier">unicode_normalized?</span>(<span class="ruby-value">:nfd</span>)  <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;\u00E0&quot;</span>.<span class="ruby-identifier">unicode_normalized?</span>         <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;\u00E0&quot;</span>.<span class="ruby-identifier">unicode_normalized?</span>(<span class="ruby-value">:nfd</span>)   <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot;\xE0&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&#39;ISO-8859-1&#39;</span>).<span class="ruby-identifier">unicode_normalized?</span>
                                     <span class="ruby-comment">#=&gt; Encoding::CompatibilityError raised</span>
</pre>
          
          

          
          <div class="method-source-code" id="unicode_normalized-3F-source">
            <pre>static VALUE
rb_str_unicode_normalized_p(int argc, VALUE *argv, VALUE str)
{
    return unicode_normalize_common(argc, argv, str, id_normalized_p);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Decodes <em>str</em> (which may contain binary data) according to the format string, returning an array of each value extracted. The format string consists of a sequence of single-character directives, summarized in the table at the end of this entry. Each directive may be followed by a number, indicating the number of times to repeat with this directive. An asterisk (“<code>*</code>&#39;&#39;) will use up all remaining elements. The directives <code>sSiIlL</code> may each be followed by an underscore (“<code>_</code>&#39;&#39;) or exclamation mark (“<code>!</code>&#39;&#39;) to use the underlying platform&#39;s native size for the specified type; otherwise, it uses a platform-independent consistent size. Spaces are ignored in the format string. See also <a href="String.html#method-i-unpack1"><code>String#unpack1</code></a>,  <a href="Array.html#method-i-pack"><code>Array#pack</code></a>.</p>

<pre class="ruby"><span class="ruby-string">&quot;abc \0\0abc \0\0&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;A6Z6&#39;</span>)   <span class="ruby-comment">#=&gt; [&quot;abc&quot;, &quot;abc &quot;]</span>
<span class="ruby-string">&quot;abc \0\0&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;a3a3&#39;</span>)           <span class="ruby-comment">#=&gt; [&quot;abc&quot;, &quot; \000\000&quot;]</span>
<span class="ruby-string">&quot;abc \0abc \0&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;Z*Z*&#39;</span>)       <span class="ruby-comment">#=&gt; [&quot;abc &quot;, &quot;abc &quot;]</span>
<span class="ruby-string">&quot;aa&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;b8B8&#39;</span>)                 <span class="ruby-comment">#=&gt; [&quot;10000110&quot;, &quot;01100001&quot;]</span>
<span class="ruby-string">&quot;aaa&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;h2H2c&#39;</span>)               <span class="ruby-comment">#=&gt; [&quot;16&quot;, &quot;61&quot;, 97]</span>
<span class="ruby-string">&quot;\xfe\xff\xfe\xff&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;sS&#39;</span>)     <span class="ruby-comment">#=&gt; [-2, 65534]</span>
<span class="ruby-string">&quot;now=20is&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;M*&#39;</span>)             <span class="ruby-comment">#=&gt; [&quot;now is&quot;]</span>
<span class="ruby-string">&quot;whole&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;xax2aX2aX1aX2a&#39;</span>)    <span class="ruby-comment">#=&gt; [&quot;h&quot;, &quot;e&quot;, &quot;l&quot;, &quot;l&quot;, &quot;o&quot;]</span>
</pre>

<p>This table summarizes the various formats and the Ruby classes returned by each.</p>

<pre>Integer       |         |
Directive     | Returns | Meaning
------------------------------------------------------------------
C             | Integer | 8-bit unsigned (unsigned char)
S             | Integer | 16-bit unsigned, native endian (uint16_t)
L             | Integer | 32-bit unsigned, native endian (uint32_t)
Q             | Integer | 64-bit unsigned, native endian (uint64_t)
J             | Integer | pointer width unsigned, native endian (uintptr_t)
              |         |
c             | Integer | 8-bit signed (signed char)
s             | Integer | 16-bit signed, native endian (int16_t)
l             | Integer | 32-bit signed, native endian (int32_t)
q             | Integer | 64-bit signed, native endian (int64_t)
j             | Integer | pointer width signed, native endian (intptr_t)
              |         |
S_ S!         | Integer | unsigned short, native endian
I I_ I!       | Integer | unsigned int, native endian
L_ L!         | Integer | unsigned long, native endian
Q_ Q!         | Integer | unsigned long long, native endian (ArgumentError
              |         | if the platform has no long long type.)
J!            | Integer | uintptr_t, native endian (same with J)
              |         |
s_ s!         | Integer | signed short, native endian
i i_ i!       | Integer | signed int, native endian
l_ l!         | Integer | signed long, native endian
q_ q!         | Integer | signed long long, native endian (ArgumentError
              |         | if the platform has no long long type.)
j!            | Integer | intptr_t, native endian (same with j)
              |         |
S&gt; s&gt; S!&gt; s!&gt; | Integer | same as the directives without &quot;&gt;&quot; except
L&gt; l&gt; L!&gt; l!&gt; |         | big endian
I!&gt; i!&gt;       |         |
Q&gt; q&gt; Q!&gt; q!&gt; |         | &quot;S&gt;&quot; is same as &quot;n&quot;
J&gt; j&gt; J!&gt; j!&gt; |         | &quot;L&gt;&quot; is same as &quot;N&quot;
              |         |
S&lt; s&lt; S!&lt; s!&lt; | Integer | same as the directives without &quot;&lt;&quot; except
L&lt; l&lt; L!&lt; l!&lt; |         | little endian
I!&lt; i!&lt;       |         |
Q&lt; q&lt; Q!&lt; q!&lt; |         | &quot;S&lt;&quot; is same as &quot;v&quot;
J&lt; j&lt; J!&lt; j!&lt; |         | &quot;L&lt;&quot; is same as &quot;V&quot;
              |         |
n             | Integer | 16-bit unsigned, network (big-endian) byte order
N             | Integer | 32-bit unsigned, network (big-endian) byte order
v             | Integer | 16-bit unsigned, VAX (little-endian) byte order
V             | Integer | 32-bit unsigned, VAX (little-endian) byte order
              |         |
U             | Integer | UTF-8 character
w             | Integer | BER-compressed integer (see Array.pack)

Float        |         |
Directive    | Returns | Meaning
-----------------------------------------------------------------
D d          | Float   | double-precision, native format
F f          | Float   | single-precision, native format
E            | Float   | double-precision, little-endian byte order
e            | Float   | single-precision, little-endian byte order
G            | Float   | double-precision, network (big-endian) byte order
g            | Float   | single-precision, network (big-endian) byte order

String       |         |
Directive    | Returns | Meaning
-----------------------------------------------------------------
A            | String  | arbitrary binary string (remove trailing nulls and ASCII spaces)
a            | String  | arbitrary binary string
Z            | String  | null-terminated string
B            | String  | bit string (MSB first)
b            | String  | bit string (LSB first)
H            | String  | hex string (high nibble first)
h            | String  | hex string (low nibble first)
u            | String  | UU-encoded string
M            | String  | quoted-printable, MIME encoding (see RFC2045)
m            | String  | base64 encoded string (RFC 2045) (default)
             |         | base64 encoded string (RFC 4648) if followed by 0
P            | String  | pointer to a structure (fixed-length string)
p            | String  | pointer to a null-terminated string

Misc.        |         |
Directive    | Returns | Meaning
-----------------------------------------------------------------
@            | ---     | skip to the offset given by the length argument
X            | ---     | skip backward one byte
x            | ---     | skip forward one byte</pre>

<p>HISTORY</p>
<ul><li>
<p>J, J! j, and j! are available since Ruby 2.3.</p>
</li><li>
<p>Q_, Q!, q_, and q! are available since Ruby 2.1.</p>
</li><li>
<p>I!&lt;, i!&lt;, I!&gt;, and i!&gt; are available since Ruby 1.9.3.</p>
</li></ul>
          
          

          
          <div class="method-source-code" id="unpack-source">
            <pre><span class="ruby-comment"># File pack.rb, line 256</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">unpack</span>(<span class="ruby-identifier">fmt</span>)
  <span class="ruby-identifier">__builtin_pack_unpack</span>(<span class="ruby-identifier">fmt</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Decodes <em>str</em> (which may contain binary data) according to the format string, returning the first value extracted. See also <a href="String.html#method-i-unpack"><code>String#unpack</code></a>, <a href="Array.html#method-i-pack"><code>Array#pack</code></a>.</p>

<p>Contrast with <a href="String.html#method-i-unpack"><code>String#unpack</code></a>:</p>

<pre class="ruby"><span class="ruby-string">&quot;abc \0\0abc \0\0&quot;</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-string">&#39;A6Z6&#39;</span>)   <span class="ruby-comment">#=&gt; [&quot;abc&quot;, &quot;abc &quot;]</span>
<span class="ruby-string">&quot;abc \0\0abc \0\0&quot;</span>.<span class="ruby-identifier">unpack1</span>(<span class="ruby-string">&#39;A6Z6&#39;</span>)  <span class="ruby-comment">#=&gt; &quot;abc&quot;</span>
</pre>

<p>In that case data would be lost but often it&#39;s the case that the array only holds one value, especially when unpacking binary data. For instance:</p>

<p>“xffx00x00x00”.unpack(“l”)         #=&gt;  [255] “xffx00x00x00”.unpack1(“l”)        #=&gt;  255</p>

<p>Thus unpack1 is convenient, makes clear the intention and signals the expected return value to those reading the code.</p>
          
          

          
          <div class="method-source-code" id="unpack1-source">
            <pre><span class="ruby-comment"># File pack.rb, line 280</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">unpack1</span>(<span class="ruby-identifier">fmt</span>)
  <span class="ruby-identifier">__builtin_pack_unpack1</span>(<span class="ruby-identifier">fmt</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns a copy of <em>str</em> with all lowercase letters replaced with their uppercase counterparts.</p>

<p>See <a href="String.html#method-i-downcase"><code>String#downcase</code></a> for meaning of <code>options</code> and use with different encodings.</p>

<pre class="ruby"><span class="ruby-string">&quot;hEllO&quot;</span>.<span class="ruby-identifier">upcase</span>   <span class="ruby-comment">#=&gt; &quot;HELLO&quot;</span>
</pre>
          
          

          
          <div class="method-source-code" id="upcase-source">
            <pre>static VALUE
rb_str_upcase(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    OnigCaseFoldType flags = ONIGENC_CASE_UPCASE;
    VALUE ret;

    flags = check_case_options(argc, argv, flags);
    enc = str_true_enc(str);
    if (case_option_single_p(flags, enc, str)) {
        ret = rb_str_new_with_class(str, RSTRING_PTR(str), RSTRING_LEN(str));
        str_enc_copy(ret, str);
        upcase_single(ret);
    }
    else if (flags&amp;ONIGENC_CASE_ASCII_ONLY) {
        ret = rb_str_new_with_class(str, 0, RSTRING_LEN(str));
        rb_str_ascii_casemap(str, ret, &amp;flags, enc);
    }
    else {
        ret = rb_str_casemap(str, &amp;flags, enc);
    }

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

        

        
      </div>

    
      <div id="method-i-upcase-21" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            upcase!              &rarr; str or nil
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            upcase!([options])   &rarr; str or nil
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Upcases the contents of <em>str</em>, returning <code>nil</code> if no changes were made.</p>

<p>See <a href="String.html#method-i-downcase"><code>String#downcase</code></a> for meaning of <code>options</code> and use with different encodings.</p>
          
          

          
          <div class="method-source-code" id="upcase-21-source">
            <pre>static VALUE
rb_str_upcase_bang(int argc, VALUE *argv, VALUE str)
{
    rb_encoding *enc;
    OnigCaseFoldType flags = ONIGENC_CASE_UPCASE;

    flags = check_case_options(argc, argv, flags);
    str_modify_keep_cr(str);
    enc = str_true_enc(str);
    if (case_option_single_p(flags, enc, str)) {
        if (upcase_single(str))
            flags |= ONIGENC_CASE_MODIFIED;
    }
    else if (flags&amp;ONIGENC_CASE_ASCII_ONLY)
        rb_str_ascii_casemap(str, str, &amp;flags, enc);
    else
        str_shared_replace(str, rb_str_casemap(str, &amp;flags, enc));

    if (ONIGENC_CASE_MODIFIED&amp;flags) return str;
    return Qnil;
}</pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-upto" class="method-detail ">
        
        
        <div class="method-heading">
          <span class="method-callseq">
            upto(other_str, exclusive=false) {|s| block }   &rarr; str
          </span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        
        <div class="method-heading">
          <span class="method-callseq">
            upto(other_str, exclusive=false)                &rarr; an_enumerator
          </span>
          
        </div>
        
        

        <div class="method-description">
          
          <p>Iterates through successive values, starting at <em>str</em> and ending at <em>other_str</em> inclusive, passing each value in turn to the block. The <a href="String.html#method-i-succ"><code>String#succ</code></a> method is used to generate each value.  If optional second argument exclusive is omitted or is false, the last value will be included; otherwise it will be excluded.</p>

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

<pre class="ruby"><span class="ruby-string">&quot;a8&quot;</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-string">&quot;b6&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-identifier">print</span> <span class="ruby-identifier">s</span>, <span class="ruby-string">&#39; &#39;</span> }
<span class="ruby-keyword">for</span> <span class="ruby-identifier">s</span> <span class="ruby-keyword">in</span> <span class="ruby-string">&quot;a8&quot;</span><span class="ruby-operator">..</span><span class="ruby-string">&quot;b6&quot;</span>
  <span class="ruby-identifier">print</span> <span class="ruby-identifier">s</span>, <span class="ruby-string">&#39; &#39;</span>
<span class="ruby-keyword">end</span>
</pre>

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

<pre class="ruby"><span class="ruby-identifier">a8</span> <span class="ruby-identifier">a9</span> <span class="ruby-identifier">b0</span> <span class="ruby-identifier">b1</span> <span class="ruby-identifier">b2</span> <span class="ruby-identifier">b3</span> <span class="ruby-identifier">b4</span> <span class="ruby-identifier">b5</span> <span class="ruby-identifier">b6</span>
<span class="ruby-identifier">a8</span> <span class="ruby-identifier">a9</span> <span class="ruby-identifier">b0</span> <span class="ruby-identifier">b1</span> <span class="ruby-identifier">b2</span> <span class="ruby-identifier">b3</span> <span class="ruby-identifier">b4</span> <span class="ruby-identifier">b5</span> <span class="ruby-identifier">b6</span>
</pre>

<p>If <em>str</em> and <em>other_str</em> contains only ascii numeric characters, both are recognized as decimal numbers. In addition, the width of string (e.g. leading zeros) is handled appropriately.</p>

<pre class="ruby"><span class="ruby-string">&quot;9&quot;</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-string">&quot;11&quot;</span>).<span class="ruby-identifier">to_a</span>   <span class="ruby-comment">#=&gt; [&quot;9&quot;, &quot;10&quot;, &quot;11&quot;]</span>
<span class="ruby-string">&quot;25&quot;</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-string">&quot;5&quot;</span>).<span class="ruby-identifier">to_a</span>   <span class="ruby-comment">#=&gt; []</span>
<span class="ruby-string">&quot;07&quot;</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-string">&quot;11&quot;</span>).<span class="ruby-identifier">to_a</span>  <span class="ruby-comment">#=&gt; [&quot;07&quot;, &quot;08&quot;, &quot;09&quot;, &quot;10&quot;, &quot;11&quot;]</span>
</pre>
          
          

          
          <div class="method-source-code" id="upto-source">
            <pre>static VALUE
rb_str_upto(int argc, VALUE *argv, VALUE beg)
{
    VALUE end, exclusive;

    rb_scan_args(argc, argv, &quot;11&quot;, &amp;end, &amp;exclusive);
    RETURN_ENUMERATOR(beg, argc, argv);
    return rb_str_upto_each(beg, end, RTEST(exclusive), str_upto_i, Qnil);
}</pre>
          </div>
          
        </div>

        

        
      </div>

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

        <div class="method-description">
          
          <p>Returns true for a string which is encoded correctly.</p>

<pre class="ruby"><span class="ruby-string">&quot;\xc2\xa1&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&quot;UTF-8&quot;</span>).<span class="ruby-identifier">valid_encoding?</span>  <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-string">&quot;\xc2&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&quot;UTF-8&quot;</span>).<span class="ruby-identifier">valid_encoding?</span>      <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-string">&quot;\x80&quot;</span>.<span class="ruby-identifier">force_encoding</span>(<span class="ruby-string">&quot;UTF-8&quot;</span>).<span class="ruby-identifier">valid_encoding?</span>      <span class="ruby-comment">#=&gt; false</span>
</pre>
          
          

          
          <div class="method-source-code" id="valid_encoding-3F-source">
            <pre>static VALUE
rb_str_valid_encoding_p(VALUE str)
{
    int cr = rb_enc_str_coderange(str);

    return cr == ENC_CODERANGE_BROKEN ? Qfalse : Qtrue;
}</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>