Class: String

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

Direct Known Subclasses

JavascriptCode

Instance Method Summary collapse

Instance Method Details

#as_identifierObject



45
46
47
48
# File 'lib/distil.rb', line 45

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

#indent(str) ⇒ Object



59
60
61
# File 'lib/distil.rb', line 59

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

#remove_indentObject



53
54
55
56
57
58
# File 'lib/distil.rb', line 53

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

#starts_with?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/distil.rb', line 49

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