Method: String#align_center
- Defined in:
- lib/core/facets/string/align.rb
#align_center(n, sep = "\n", c = ' ') ⇒ Object
Centers each line of a string.
The default alignment separation is a new line (“n”). This can be changed as can be the padding string which defaults to a single space (‘ ’).
s = <<-EOS
This is a test
and
so on
EOS
s.align_center(14)
produces …
This is a test
and
so on
CREDIT: Trans
116 117 118 119 120 121 122 |
# File 'lib/core/facets/string/align.rb', line 116 def align_center(n, sep="\n", c=' ') return center(n.to_i,c.to_s) if sep==nil q = split(sep.to_s).collect { |line| line.center(n.to_i,c.to_s) } q.join(sep.to_s) end |