Justify at both sides : Justify Right « String « Ruby






Justify at both sides


title = "Love's Labours Lost"

title.rjust(20, "-").ljust(21, "-") # => "-Love's Labours Lost-"

 








Related examples in the same category

1.Use another character besides the default space character if you'd like
2.Use more than one character the sequence will be repeated
3.Add to both sides