Skip to content

Instantly share code, notes, and snippets.

@julik
Created October 23, 2010 11:56
Show Gist options
  • Save julik/642127 to your computer and use it in GitHub Desktop.
Save julik/642127 to your computer and use it in GitHub Desktop.
require "delegate"
class EDL::LinebreakMagician < DelegateClass(IO)
def initialize(with_file)
sample = with_file.read(2048)
@linebreak = ["\r\n", "\r", "\n"].find{|separator| sample.include?(separator) }
with_file.rewind
__setobj__(with_file)
end
def each(sep_string = $/, &blk)
super(@linebreak || sep_string, &blk)
end
alias_method :each_line, :each
def gets(sep_string = $/)
super(@linebreak || sep_string)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment