Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/coherent.rb
Instance Method Summary collapse
- #as_identifier ⇒ Object
- #indent(str) ⇒ Object
- #remove_indent ⇒ Object
- #starts_with?(prefix) ⇒ Boolean
Instance Method Details
#as_identifier ⇒ Object
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_indent ⇒ Object
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 |