Justifies a string in a certain way. Valid values for way are
:right,:left and :center.
Is primarily used as a helper method by rjust,ljust
and center.
# File activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb, line 427
def justify(str, integer, way, padstr=' ')
raise ArgumentError, "zero width padding" if padstr.length == 0
padsize = integer - size(str)
padsize = padsize > 0 ? padsize : 0
case way
when :right
str.dup.insert(0, padding(padsize, padstr))
when :left
str.dup.insert(-1, padding(padsize, padstr))
when :center
lpad = padding((padsize / 2.0).floor, padstr)
rpad = padding((padsize / 2.0).ceil, padstr)
str.dup.insert(0, lpad).insert(-1, rpad)
end
end