Sha256: faaaa1238d16cb96c87ed54c06911f92a61f4bbb195ab83cddf424732319ba54

Contents?: true

Size: 618 Bytes

Versions: 3

Compression:

Stored size: 618 Bytes

Contents

module String::Cleanlines
  refine String do
    # Copied from acets/string/cleanlines.rb

    # Returns an Enumerator for iterating over each
    # line of the string, stripped of whitespace on
    # either side.
    #
    #   "this\nthat\nother\n".cleanlines.to_a  #=> ['this', 'that', 'other']
    #
    def cleanlines(&block)
      if block
        scan(/^.*?$/) do |line|
          block.call(line.strip)
        end
      else
        str = self
        Enumerator.new do |output|
          str.scan(/^.*?$/) do |line|
            output.yield(line.strip)
          end
        end
      end
    end
  end
end


Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
address_concern-3.0.0 lib/core_extensions/string/cleanlines.rb
address_concern-2.1.1 lib/core_extensions/string/cleanlines.rb
address_concern-2.1.0 lib/core_extensions/string/cleanlines.rb