title: Ruby: Remove whitespace chars at the beginning of a string
body: <p>Edit: I solved this by using <code>strip!</code> to <a href="https://www.youtube.com/watch?v=Ef_hGfJGt3U" rel="nofollow noreferrer">remove leading and trailing whitespaces as I show in this video</a>. Then, I followed up by restoring the white space at the end of each string the array by iterating through and adding whitespace. This problem varies from the &quot;dupe&quot; as <strong>my intent is to keep the whitespace at the end</strong>. However, strip! will remove both the leading and trailing whitespace if that is your intent. (I would have made this an answer, but as this is incorrectly marked as a dupe, I could only edit my original question to include this.)</p>
  <p>I have an array of words where I am trying to remove any whitespace that may exist at the beginning of the word instead of at the end. rstrip! just takes care of the end of a string. I want whitespaces removed from the beginning of a string.</p>
  <pre><code>example_array = ['peanut', ' butter', 'sammiches']
  desired_output = ['peanut', 'butter', 'sammiches']
  </code></pre>
  <p>As you can see, not all elements in the array have the whitespace problem, so I can't just delete the first character as I would if all elements started with a single whitespace char.</p>
  <p>Full code:</p>
  <pre><code>words = params[:word].gsub(&quot;\n&quot;, &quot;,&quot;).delete(&quot;\r&quot;).split(&quot;,&quot;)
  words.delete_if {|x| x == &quot;&quot;}
  words.each do |e|
    e.lstrip!
  end
  </code></pre>
  <p>Sample text that a user may enter on the form:</p>
  <pre><code>Corn on the cob,
  Fibonacci,
  StackOverflow
  Chat, Meta, About
  Badges
  Tags,,
  Unanswered
  Ask Question
  </code></pre>