Sha256: 12ed8aa9d80509e95755517040d229140592feb72840e9fa4619217c1fbe63ce

Contents?: true

Size: 286 Bytes

Versions: 17

Compression:

Stored size: 286 Bytes

Contents

require 'facets/string/indent'

class String

  # Preserves relative tabbing.
  # The first non-empty line ends up with n spaces before nonspace.
  #
  # CREDIT: Gavin Sinclair

  def tabto(n)
    if self =~ /^( *)\S/
      indent(n - $1.length)
    else
      self
    end
  end

end

Version data entries

17 entries across 16 versions & 1 rubygems

Version Path
facets-2.9.3 lib/core/facets/string/tabto.rb
facets-2.9.2 src/core/facets/string/tabto.rb
facets-2.9.2 lib/core/facets/string/tabto.rb
facets-2.9.1 lib/core/facets/string/tabto.rb
facets-2.9.0 lib/core/facets/string/tabto.rb
facets-2.9.0.pre.2 lib/core/facets/string/tabto.rb
facets-2.9.0.pre.1 lib/core/facets/string/tabto.rb
facets-2.8.4 lib/core/facets/string/tabto.rb
facets-2.8.3 lib/core/facets/string/tabto.rb
facets-2.8.2 lib/core/facets/string/tabto.rb
facets-2.8.1 lib/core/facets/string/tabto.rb
facets-2.8.0 lib/core/facets/string/tabto.rb
facets-2.7.0 lib/core/facets/string/tabto.rb
facets-2.6.0 lib/core/facets/string/tabto.rb
facets-2.5.1 lib/core/facets/string/tabto.rb
facets-2.5.0 lib/core/facets/string/tabto.rb
facets-2.5.2 lib/core/facets/string/tabto.rb