Class String
In: lib/clio/facets/string.rb
Parent: Object

Methods

indent   tabto  

Public Instance methods

Indent left or right by n spaces. (This used to be called tab and aliased as indent.)

[Source]

# File lib/clio/facets/string.rb, line 6
  def indent(n)
    if n >= 0
      gsub(/^/, ' ' * n)
    else
      gsub(/^ {0,#{-n}}/, "")
    end
  end

Preserves relative tabbing. The first non-empty line ends up with n spaces before nonspace.

[Source]

# File lib/clio/facets/string.rb, line 17
  def tabto(n)
    if self =~ /^( *)\S/
      indent(n - $1.length)
    else
      self
    end
  end

[Validate]