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):
File.open("test.txt", "w+") do |f| a.each { |element| f.puts(element) } end
Or pass the whole array to puts:
File.open("test.txt", "w+") do |f| f.puts(a) end
Source –http://stackoverflow.com/questions/18900474/add-each-array-element-to-the-lines-of-a-file-in-ruby
Latest posts by scmgalaxy K (see all)
- Use of runtime variables to save into another variable using register in Ansible - September 6, 2018
- Ansible & Ansible Tower Variable Precedence Hierarchy - September 6, 2018
- How to use template in Ansible? - September 6, 2018