Skip to content

Instantly share code, notes, and snippets.

@donilan
Created December 24, 2015 06:38
Show Gist options
  • Save donilan/515889f6c6eb6bf69309 to your computer and use it in GitHub Desktop.
Save donilan/515889f6c6eb6bf69309 to your computer and use it in GitHub Desktop.
A ruby CSV class that extends build-in CSV and add ability that keeping original line
require 'csv'
class MyCsv < CSV
# The line of the last row read from this file.
attr_reader :line
def shift
if @_before_lineno != @lineno
@_before_pos = pos
@_before_lineno = @lineno
end
row = super
after_pos = pos
@io.pos = @_before_pos
@line = @io.read(after_pos - @_before_pos)
row
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment