Search code examples
rubyarrayschomp

How can I chomp every line in an array at once?


In the interest of writing cleaner code...

IO.popen("Generate a list of files").readlines.each{ |line|
   chomped_line = line.chomp
   # ...
}

Solution

  • IO.popen("Generate a list of files").readlines.map(&:chomp)