I'm using Ruby 2.4. I want to strip off nil
elements from the end of an array, so I'm using
row_data.pop until row_data.last
but if the array only contains nil
elements, this seems to cause some kind of infinite loop because the call never returns. How do I account for the fact that the array might contain all nil elements?
Answer
Just add an extra check to see if the array is empty.
row_data.pop until row_data.last || row_data.empty?
No comments:
Post a Comment