Class: IO
Overview
IO extensions
Class Method Summary collapse
-
.readrows(filename, options = {}) ⇒ Array<Array<String>>
Reads the entire file specified by name as individual lines as with IO#readlines, and returns those lines in an array of rows, where each row is an array of fields.
Instance Method Summary collapse
-
#readrow(options = {}) ⇒ Array<String>
Read a line as with IO#readline and return the line as a row of fields.
Class Method Details
.readrows(filename, options = {}) ⇒ Array<Array<String>>
Reads the entire file specified by name as individual lines as with IO#readlines, and returns those lines in an array of rows, where each row is an array of fields.
Note: the col option is sent along to String#split, so can be a string or a regexp.
-
File#readline
-
File#readlines
-
File#readrow
32 33 34 35 36 |
# File 'lib/sixarm_ruby_ramp/io.rb', line 32 def IO.readrows(filename, ={}) row_sep||=[:row]||$/||"\n" col_sep||=[:col]||$;||"\t" return IO.readlines(filename, row_sep).map{|line| line.chomp(row_sep).split(col_sep)} end |
Instance Method Details
#readrow(options = {}) ⇒ Array<String>
Read a line as with IO#readline and return the line as a row of fields.
Note: the col option is sent along to String#split, so can be a string or a regexp.
-
Rows are separated by row option, which defaults to Ruby’s record separator $/ or “n”
-
Cols are separated by col option, which defaults to Ruby’s string split separator $; or “t”
65 66 67 68 69 |
# File 'lib/sixarm_ruby_ramp/io.rb', line 65 def readrow(={}) row_sep||=[:row]||$/||"\n" col_sep||=[:col]||$;||"\t" return readline(row_sep).chomp(row_sep).split(col_sep) end |