Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/clio/facets/string.rb
Instance Method Summary collapse
-
#indent(n) ⇒ Object
Indent left or right by n spaces.
-
#tabto(n) ⇒ Object
Preserves relative tabbing.
Instance Method Details
#indent(n) ⇒ Object
Indent left or right by n spaces. (This used to be called #tab and aliased as #indent.)
6 7 8 9 10 11 12 |
# File 'lib/clio/facets/string.rb', line 6 def indent(n) if n >= 0 gsub(/^/, ' ' * n) else gsub(/^ {0,#{-n}}/, "") end end |
#tabto(n) ⇒ Object
Preserves relative tabbing. The first non-empty line ends up with n spaces before nonspace.
17 18 19 20 21 22 23 |
# File 'lib/clio/facets/string.rb', line 17 def tabto(n) if self =~ /^( *)\S/ indent(n - $1.length) else self end end |