scmuser created the topic: Add each array element to the lines of a file in ruby
Add each array element to the lines of a file in ruby
Either use Array#each to iterate over your array and call IO#puts to write each element to the file (puts adds a record separator, typically a newline character):
[code language=βcssβ]
File.open(βtest.txtβ, βw+β) do |f|
a.each { |element| f.puts(element) }
end
[/code]
Or pass the whole array to puts:
[code language=βcssβ]
File.open(βtest.txtβ, βw+β) do |f|
f.puts(a)
end
[/code]
Source βhttp://stackoverflow.com/questions/18900474/add-each-array-element-to-the-lines-of-a-file-in-ruby
Iβm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND