Sha256: 495e8eaa6bdba5d652f0eefd19c17e1ef16804af93f5a7345dab850268059536

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

== String#unindent

  require 'facets/string/unindent'

We will use these two strings as a common basis for demonstration.

  ex1 = <<-EOF.gsub(/^\s*\|/,'')
  |    I must go down to the seas again
  |      The lonely sea and the sky
  |    And all I want is a tall ship
  |      And a star to steer her by
  EOF

  ex2 = <<-EOF.gsub(/^\s*\|/,'')
  |     "Eek!"
  |  She cried
  |    As the mouse quietly scurried
  |by.
  EOF

simple examples

  "   xyz".unindent(-1).assert == "    xyz"
  "   xyz".unindent(0).assert  == "   xyz"
  "   xyz".unindent(1).assert  == "  xyz"
  "   xyz".unindent(2).assert  == " xyz"
  "   xyz".unindent(3).assert  == "xyz"
  "   xyz".unindent(4).assert  == "xyz"

large example unindented one space

  expected = <<-EOF.gsub(/^\s*\|/,'')
  |   I must go down to the seas again
  |     The lonely sea and the sky
  |   And all I want is a tall ship
  |     And a star to steer her by
  EOF

  actual = ex1.unindent(1)
  actual.assert == expected

large example unindented four spaces

  expected = <<-EOF.gsub(/^\s*\|/,'')
  |I must go down to the seas again
  |  The lonely sea and the sky
  |And all I want is a tall ship
  |  And a star to steer her by
  EOF

  actual = ex1.unindent(4)
  actual.assert == expected

unindent larger than current indention

  expected = <<-EOF.gsub(/^\s*\|/,'')
  |"Eek!"
  |She cried
  |As the mouse quietly scurried
  |by.
  EOF

  actual = ex2.unindent(100)
  actual.assert == expected

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
facets-3.0.0 demo/core/string/unindent.rdoc
facets-2.9.3 qed/core/string/unindent.rdoc
facets-2.9.2 qed/core/string/unindent.rdoc
facets-2.9.1 qed/core/string/unindent.rdoc
facets-2.9.0 qed/core/string/unindent.rdoc
facets-2.9.0.pre.2 qed/core/string/unindent.rdoc
facets-2.9.0.pre.1 qed/core/string/unindent.rdoc