Class: IO
Instance Method Summary collapse
-
#read_lines ⇒ Array<String>
Reads from the IO all lines, and returns them as an array, end-of-line characters excluded.
-
#write_lines(lines) ⇒ Enumerable<#to_s>
Writes each object as a string plus a succeeding new line character (
$/) to the IO.
Instance Method Details
#read_lines ⇒ Array<String>
Reads from the IO all lines, and returns them as an array, end-of-line characters excluded. The $/ global string specifies what end-of-line characters to exclude.
(Not to be confused with IO#readlines which retains end-of-line characters in every string it returns.)
41 42 43 |
# File 'lib/pleasant_path/io.rb', line 41 def read_lines self.readlines.each(&:chomp!) end |
#write_lines(lines) ⇒ Enumerable<#to_s>
Writes each object as a string plus a succeeding new line character ($/) to the IO. Returns the objects unmodified.
16 17 18 19 20 21 22 23 |
# File 'lib/pleasant_path/io.rb', line 16 def write_lines(lines) lines.each do |line| self.write(line) self.write($/) end self.write("") # write something even if no lines lines end |