Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/coherent.rb

Instance Method Summary collapse

Instance Method Details

#as_identifierObject



4
5
6
7
# File 'lib/coherent.rb', line 4

def as_identifier
  word= self.to_s.gsub(/(?:^|\W)(.)/) { $1.upcase }
  # word[0..0].downcase + word[1..-1]
end

#indent(str) ⇒ Object



18
19
20
# File 'lib/coherent.rb', line 18

def indent(str)
  self.gsub(/^/, str)
end

#remove_indentObject



12
13
14
15
16
17
# File 'lib/coherent.rb', line 12

def remove_indent
  str= sub(/^\n*/, "")
  match= str.match(/(^\s+)/)
  return str unless match
  str.gsub(/^#{match[1]}/, '').strip
end

#starts_with?(prefix) ⇒ Boolean

word.downcase + word

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/coherent.rb', line 8

def starts_with?(prefix)
  prefix = prefix.to_s
  self[0, prefix.length] == prefix
end