Ruby: Write Array elements as new line


2018-01-17 · 1 min read

Use puts with an array argument to write each elements on a new line:

arr = %w[a b c]

File.open("array.txt", "w+") do |f|
  f.puts(a)
end

Subscribe to My Newsletter

The latest programming-related news, articles and resources - sent to your inbox monthly. Unsubscribe anytime.