<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Say what???: Ruby Method of the Day - String.rstrip</title>
    <link>http://drotner.org/articles/2007/09/25/ruby-method-of-the-day-string-right-strip</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>by Kelly McCauley</description>
    <item>
      <title>Ruby Method of the Day - String.rstrip</title>
      <description>&lt;h3&gt;Signature&lt;/h3&gt;




&lt;div class="CodeRay"&gt;
  &lt;div class="code"&gt;&lt;pre&gt;string.rstrip   &lt;span class="c"&gt;#=&amp;gt; new_string&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;&lt;code&gt;String.rstrip&lt;/code&gt; is the counter whitespace removal method to
&lt;a href="http://drotner.org/articles/2007/09/21/ruby-method-of-the-day-string-left-strip"&gt;&lt;code&gt;String.lstrip&lt;/code&gt;&lt;/a&gt;.
&lt;code&gt;string.rstrip&lt;/code&gt; returns a new string with trailing whitespace removed.&lt;/p&gt;

	&lt;h3&gt;Examples&lt;/h3&gt;




&lt;table class="CodeRay"&gt;&lt;tr&gt;
  &lt;td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"&gt;&lt;pre&gt;1&lt;tt&gt;
&lt;/tt&gt;2&lt;tt&gt;
&lt;/tt&gt;3&lt;tt&gt;
&lt;/tt&gt;4&lt;tt&gt;
&lt;/tt&gt;5&lt;tt&gt;
&lt;/tt&gt;6&lt;tt&gt;
&lt;/tt&gt;7&lt;tt&gt;
&lt;/tt&gt;8&lt;tt&gt;
&lt;/tt&gt;9&lt;tt&gt;
&lt;/tt&gt;&lt;strong&gt;10&lt;/strong&gt;&lt;tt&gt;
&lt;/tt&gt;11&lt;tt&gt;
&lt;/tt&gt;12&lt;tt&gt;
&lt;/tt&gt;13&lt;tt&gt;
&lt;/tt&gt;14&lt;tt&gt;
&lt;/tt&gt;15&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
  &lt;td class="code"&gt;&lt;pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }"&gt;&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;foo bar  &lt;/span&gt;&lt;span class="ch"&gt;\r&lt;/span&gt;&lt;span class="ch"&gt;\n&lt;/span&gt;&lt;span class="ch"&gt;\t&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;.rstrip    &lt;span class="c"&gt;#=&amp;gt; &amp;quot;foo bar&amp;quot;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;text = &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;lt;&amp;lt;-&amp;quot;END&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class="s"&gt;&lt;span class="k"&gt;&lt;tt&gt;
&lt;/tt&gt;      Lorem ipsum dolor sit amet, consectetuer      &lt;/span&gt;&lt;span class="ch"&gt;\t&lt;/span&gt;&lt;span class="k"&gt;&lt;tt&gt;
&lt;/tt&gt;      adipiscing elit. Ut ac nulla.  Duis sed est.  &lt;/span&gt;&lt;span class="ch"&gt;\t&lt;/span&gt;&lt;span class="k"&gt;&lt;tt&gt;
&lt;/tt&gt;      Praesent at dui et velit tempor cursus.       &lt;/span&gt;&lt;span class="ch"&gt;\t&lt;/span&gt;&lt;span class="k"&gt;&lt;tt&gt;
&lt;/tt&gt;      Morbi purus tortor, tempus tincidunt,         &lt;/span&gt;&lt;span class="ch"&gt;\t&lt;/span&gt;&lt;span class="k"&gt;&lt;tt&gt;
&lt;/tt&gt;      placerat sit amet, dignissim quis, nulla.     &lt;/span&gt;&lt;span class="ch"&gt;\t&lt;/span&gt;&lt;span class="k"&gt;&lt;tt&gt;
&lt;/tt&gt;      Duis ipsum. Proin fringilla.&lt;/span&gt;&lt;span class="dl"&gt;&lt;tt&gt;
&lt;/tt&gt;END&lt;/span&gt;&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="c"&gt;# Prints out each line of the obove paragraph with&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="c"&gt;# trailing whitespace removed and the string '[eol]'&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;&lt;span class="c"&gt;# appended to the end of the line.&lt;/span&gt;&lt;tt&gt;
&lt;/tt&gt;text.each_line{|l| puts l.rstrip &amp;lt;&amp;lt; &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;[eol]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;}&lt;tt&gt;
&lt;/tt&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;/table&gt;



	&lt;h3&gt;Documentation Reference&lt;/h3&gt;


	&lt;p&gt;&lt;a href="http://www.ruby-doc.org"&gt;www.ruby-doc.org&lt;/a&gt; : &lt;a href="http://www.ruby-doc.org/core/classes/String.html#M000837"&gt;String.rstrip&lt;/a&gt;&lt;/p&gt;


</description>
      <pubDate>Tue, 25 Sep 2007 00:01:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:aa9ff609-645e-4f68-99b7-57158bfb4ed5</guid>
      <author>Kelly McCauley</author>
      <link>http://drotner.org/articles/2007/09/25/ruby-method-of-the-day-string-right-strip</link>
      <category>Ruby Method of the Day</category>
      <category>Programming</category>
      <category>ruby</category>
      <category>rmotd</category>
    </item>
  </channel>
</rss>
