Ruby/String/Justify Right

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

Версия от 17:10, 26 мая 2010; (Обсуждение)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Содержание

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, "->"