Method: CSV.parse
- Defined in:
- lib/csv.rb
.parse(*args, &block) ⇒ Object
:call-seq:
parse( str, ** ) { |row| ... }
parse( str, ** )
This method can be used to easily parse CSV out of a String. You may either provide a block
which will be called with each row of the String in turn, or just use the returned Array of Arrays (when no block
is given).
You pass your str
to read from, and an optional options
containing anything CSV::new() understands.
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 |
# File 'lib/csv.rb', line 1310 def self.parse(*args, &block) csv = new(*args) if block.nil? # slurp contents, if no block is given begin csv.read ensure csv.close end else # or pass each row to a provided block csv.each(&block) end end |