Class: String

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

Overview

Instance Method Summary collapse

Instance Method Details

#force_encoding(encoding) ⇒ Object



29
30
31
# File 'lib/ruco/core_ext/string.rb', line 29

def force_encoding(encoding)
  self
end

#indexes(needle) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/ruco/core_ext/string.rb', line 43

def indexes(needle)
  found = []
  current_index = -1
  while current_index = index(needle, current_index+1)
    found << current_index
  end
  found
end

#leading_whitespaceObject



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

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

#leading_whitespace=(whitespace) ⇒ Object



23
24
25
# File 'lib/ruco/core_ext/string.rb', line 23

def leading_whitespace=(whitespace)
  sub!(/^\s*/, whitespace)
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



35
36
37
# File 'lib/ruco/core_ext/string.rb', line 35

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