Module: ArrayInFile
- Defined in:
- lib/array_in_file.rb,
lib/array_in_file/version.rb
Constant Summary collapse
- VERSION =
"0.0.0"
Class Method Summary collapse
-
.read(path) ⇒ Object
Reads contents of file into a string Newlines denote the break between array elements.
-
.write(array_to_write, path) ⇒ Object
Writes an array into a file Newlines denote the break between array elements.
Class Method Details
.read(path) ⇒ Object
Reads contents of file into a string Newlines denote the break between array elements
7 8 9 10 11 |
# File 'lib/array_in_file.rb', line 7 def self.read (path) array1 = File.open(path, "r").read.split("\n") array1.delete '' return array1 end |
.write(array_to_write, path) ⇒ Object
Writes an array into a file Newlines denote the break between array elements
15 16 17 18 19 20 21 |
# File 'lib/array_in_file.rb', line 15 def self.write (array_to_write, path) f = File.open(path, 'w') array_to_write.each do |element| f.puts (element.to_s) end f.close end |