Sha256: d30b503483bcdd458f63af18b5708c85f64332c0af8a8282498f7bb9a5a15989

Contents?: true

Size: 919 Bytes

Versions: 17

Compression:

Stored size: 919 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 tabs_to_spaces!
    gsub!("\t",' ' * Ruco::TAB_SIZE)
  end

  def leading_whitespace
    match(/^\s*/)[0]
  end

  def leading_whitespace=(whitespace)
    sub!(/^\s*/, whitespace)
  end

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

  unless method_defined?(:ord)
    def ord
      bytes.first
    end
  end
end

# http://grosser.it/2010/12/31/ruby-string-indexes-indices-find-all-indexes-in-a-string
class String
  def indexes(needle)
    found = []
    current_index = -1
    while current_index = index(needle, current_index+1)
      found << current_index
    end
    found
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ruco-0.1.8 lib/ruco/core_ext/string.rb
ruco-0.1.7 lib/ruco/core_ext/string.rb
ruco-0.1.6 lib/ruco/core_ext/string.rb
ruco-0.1.5 lib/ruco/core_ext/string.rb
ruco-0.1.4 lib/ruco/core_ext/string.rb
ruco-0.1.3 lib/ruco/core_ext/string.rb
ruco-0.1.2 lib/ruco/core_ext/string.rb
ruco-0.1.1 lib/ruco/core_ext/string.rb
ruco-0.1.0 lib/ruco/core_ext/string.rb
ruco-0.0.56 lib/ruco/core_ext/string.rb
ruco-0.0.55 lib/ruco/core_ext/string.rb
ruco-0.0.54 lib/ruco/core_ext/string.rb
ruco-0.0.53 lib/ruco/core_ext/string.rb
ruco-0.0.52 lib/ruco/core_ext/string.rb
ruco-0.0.51 lib/ruco/core_ext/string.rb
ruco-0.0.50 lib/ruco/core_ext/string.rb
ruco-0.0.49 lib/ruco/core_ext/string.rb