In the interest of writing cleaner code...
IO.popen("Generate a list of files").readlines.each{ |line|
chomped_line = line.chomp
# ...
}
IO.popen("Generate a list of files").readlines.map(&:chomp)
# Example 1
File.readlines("file.txt").each{|line| line.chomp!}
# Example 2
File.readlines("file.txt").map(&:chomp)
# Example 3
File.open("file.txt", "r"){|file| file.readlines.collect{|line| line.chomp}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With