Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/distil.rb
Direct Known Subclasses
Instance Method Summary collapse
- #as_identifier ⇒ Object
- #indent(str) ⇒ Object
- #remove_indent ⇒ Object
- #starts_with?(prefix) ⇒ Boolean
Instance Method Details
#as_identifier ⇒ Object
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_indent ⇒ Object
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
49 50 51 52 |
# File 'lib/distil.rb', line 49 def starts_with?(prefix) prefix = prefix.to_s self[0, prefix.length] == prefix end |