Class: String

Inherits:
Object show all
Defined in:
lib/ruco/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#force_encoding(encoding) ⇒ Object



25
26
27
# File 'lib/ruco/core_ext/string.rb', line 25

def force_encoding(encoding)
  self
end

#leading_whitespaceObject



19
20
21
# File 'lib/ruco/core_ext/string.rb', line 19

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

#naive_split(pattern) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/ruco/core_ext/string.rb', line 2

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

#ordObject



31
32
33
# File 'lib/ruco/core_ext/string.rb', line 31

def ord
  bytes.first
end

#tabs_to_spaces!Object



15
16
17
# File 'lib/ruco/core_ext/string.rb', line 15

def tabs_to_spaces!
  gsub!("\t",' ' * Ruco::TAB_SIZE)
end