Sha256: 7ef3c293084c00717ed080c4bf03f9099bf065240af1bdd0df8902f810adc7eb

Contents?: true

Size: 384 Bytes

Versions: 5

Compression:

Stored size: 384 Bytes

Contents

class String

  # Indent left or right by n spaces.
  # (This used to be called #tab and aliased as #indent.)
  #
  # CREDIT: Gavin Sinclair, Trans

  def indent(n)
    if n >= 0
      gsub(/^/, ' ' * n)
    else
      gsub(/^ {0,#{-n}}/, "")
    end
  end

  # Outdent just indents a negative number of spaces.
  #
  # CREDIT: Noah Gibbs

  def outdent(n)
    indent(-n)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
facets-2.7.0 lib/core/facets/string/indent.rb
facets-2.6.0 lib/core/facets/string/indent.rb
facets-2.5.0 lib/core/facets/string/indent.rb
facets-2.5.1 lib/core/facets/string/indent.rb
facets-2.5.2 lib/core/facets/string/indent.rb