Sha256: cb92c0840545004a21c9c770edb70aebe844bcbc09a5ca69aa7db93154ba6e07

Contents?: true

Size: 404 Bytes

Versions: 9

Compression:

Stored size: 404 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
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ruco-0.0.12 lib/ruco/core_ext/string.rb
ruco-0.0.11 lib/ruco/core_ext/string.rb
ruco-0.0.10 lib/ruco/core_ext/string.rb
ruco-0.0.9 lib/ruco/core_ext/string.rb
ruco-0.0.8 lib/ruco/core_ext/string.rb
ruco-0.0.7 lib/ruco/core_ext/string.rb
ruco-0.0.6 lib/ruco/core_ext/string.rb
ruco-0.0.5 lib/ruco/core_ext/string.rb
ruco-0.0.4 lib/ruco/core_ext/string.rb