Sha256: 2acf64a5bc45bba3a6fe81dccf871320b8bad3f4b0cd7a8420236c4400083ebd

Contents?: true

Size: 522 Bytes

Versions: 7

Compression:

Stored size: 522 Bytes

Contents

class String
  def naive_split(pattern)
    string = self.dup
    found = []

    while position = string.index(pattern)
      found << string.slice!(0, position)
      string.slice!(0,[pattern.size,1].max)
    end

    found << string
    found
  end

  def nth_index(text, n)
    offset = -1
    (n+1).times do
      offset += 1
      offset = index(text, offset) or return
    end
    offset
  end

  # stub for 1.8
  unless method_defined?(:force_encoding)
    def force_encoding(encoding)
      self
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ruco-0.0.19 lib/ruco/core_ext/string.rb
ruco-0.0.18 lib/ruco/core_ext/string.rb
ruco-0.0.17 lib/ruco/core_ext/string.rb
ruco-0.0.16 lib/ruco/core_ext/string.rb
ruco-0.0.15 lib/ruco/core_ext/string.rb
ruco-0.0.14 lib/ruco/core_ext/string.rb
ruco-0.0.13 lib/ruco/core_ext/string.rb