Created
December 24, 2015 06:38
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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