RCR: String#indent(n)

I need to check, but I think that most of what you’re looking for is in Text::Format.

-a

···


austin ziegler
Sent from my Treo

-----Original Message-----
From: Gavin Sinclair
Date: 03.1.13 22.27
To: ruby-talk@ruby-lang.org (ruby-talk ML)
Subj: RCR: String#indent(n)

Rubyists,

I think a fine companion for String#ljust, String#rjust and
String#center would be String#indent.

For example:

text = <<EOT
I must go down to the sea again
The lonely sea and sky
And all I want is a tall ship
And a star to steer me by
EOT

text.indent(4) == <<EOT # -> true
I must go down to the sea again
The lonely sea and sky
And all I want is a tall ship
And a star to steer me by
EOT

text.indent("-± ") == <<EOT # -> true
-± I must go down to the sea again
-± The lonely sea and sky
-± And all I want is a tall ship
-± And a star to steer me by
EOT

Note that the above code is demonstration only; I haven’t run it.

It would probably be better in hindsight to move #ljust et al into a
separate module (StringFormat, say) with which individual objects can
be extended at will. Then more and more utility methods can be added
without bloating String.

Gavin

Gavin,

I will make these changes to the next version of Text::Format.

-austin (also planning on simplifying some of the uses of
Text::Format)
– Austin Ziegler, austin@halostatue.ca on 2003.01.14 at 19.42.54