lib/polyfill/v2_4/io/instance/each_line.rb in polyfill-0.3.0 vs lib/polyfill/v2_4/io/instance/each_line.rb in polyfill-0.4.0

- old
+ new

@@ -1,65 +1,52 @@ +require 'English' + module Polyfill module V2_4 module IO module Instance module EachLine module Method def each_line(*args) hash, others = args.partition { |arg| arg.is_a?(::Hash) } - chomps = hash[0] && hash[0][:chomp] unless block_given? - if chomps - separator = others.find { |other| other.respond_to?(:to_str) } + return super(*others) unless chomps - return Enumerator.new do |yielder| - block = - if separator - Proc.new do |line| - yielder.yield(line.chomp(separator)) - end - else - Proc.new do |line| - yielder.yield(line.chomp) - end - end - super(*others, &block) + separator = others.find do |other| + other.respond_to?(:to_str) + end || $INPUT_RECORD_SEPARATOR + return ::Enumerator.new do |yielder| + super(*others) do |line| + yielder.yield(line.chomp(separator)) end - else - return super(*others) end end block = if chomps - separator = others.find { |other| other.respond_to?(:to_str) } - if separator - Proc.new do |line| - yield(line.chomp(separator)) - end - else - Proc.new do |line| - yield(line.chomp) - end + separator = others.find do |other| + other.respond_to?(:to_str) + end || $INPUT_RECORD_SEPARATOR + + proc do |line| + yield(line.chomp(separator)) end else Proc.new end super(*others, &block) end end - if RUBY_VERSION < '2.4.0' - refine ::IO do - include Method - end + refine ::IO do + include Method + end - def self.included(base) - base.include Method - end + def self.included(base) + base.include Method end end end end end