Sathish Manohar Sathish Manohar - 2 months ago 10
Ruby Question

How to align ruby string to left or right?

I have few ruby strings, which I want to align left and right appropriately.

I'm now using

"Name".center(20, " ")
to get
"(7 spaces)Name(8 spaces)"


How can I achieve
"Name(15 spaces)"
or
"(15 spaces)Name"


Thanks.

Answer
"Name".ljust(19)
"Name".rjust(19)
Comments