title: Remove trailing nil values from array in ruby
body: <p>I have an array something like this:</p>
  
  <pre><code>[["a", nil, nil, nil], ["b", nil, "c", nil], [nil, nil, nil, nil]]
  </code></pre>
  
  <p>I want to remove all trailing nil values from array in ruby.</p>
  
  <p>I tried <code>arr.map {|x| x.pop until x.last}</code> but the problem with this approach is that when all the value of arrays are nil like in 3rd array in given array, the loop stucks. </p>
  
  <p>Because of the <code>until x.last</code> condition, If all the values are nil then the map function should return me an empty array?</p>
  
  <p>What should be the conditions for this.</p>
  
  <p>The output should be</p>
  
  <pre><code>[['a'],['b','nil','c'],[]]
  </code></pre>
  
  <p>Remember I just want to remove trailing <code>nil</code> values not in between. </p>