Ruby/String/Justify Right

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Содержание

Add to both sides

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



Justify at both sides

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



Use another character besides the default space character if you"d like

title = "Love"s Labours Lost"
puts title.rjust( 21, "-" )



Use more than one character the sequence will be repeated

title = "Love"s Labours Lost"
puts title.rjust 25, "->"