Sha256: 3720aadacb1706854ae8e0e55dbd2bc5289b4a86b504d678be98a3c7f145fcf7

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

require 'English'

module Polyfill
  module V2_4
    module String
      module Instance
        module Lines
          module Method
            def lines(*args)
              hash, others = args.partition { |arg| arg.is_a?(::Hash) }
              chomps = hash[0] && hash[0][:chomp]

              unless block_given?
                lines = super(*others)

                if chomps
                  separator = others.find do |other|
                    other.respond_to?(:to_str)
                  end || $INPUT_RECORD_SEPARATOR

                  lines.each { |line| line.chomp!(separator) }
                end

                return lines
              end

              block =
                if chomps
                  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

          refine ::String do
            include Method
          end

          def self.included(base)
            base.include Method
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
polyfill-0.5.0 lib/polyfill/v2_4/string/instance/lines.rb
polyfill-0.4.0 lib/polyfill/v2_4/string/instance/lines.rb