Ruby/String/Justify Center
Материал из Wiki.crossplatform.ru
Содержание |
Center a string
title = "Love"s Labours Lost" title.center 23 # => " Love"s Labours Lost "
Center a string by filling
title = "Love"s Labours Lost" title.center 23, "-" # => "--Love"s Labours Lost--"
one space longer than the word
"four".center(5) # => "four " "four".center(6) # => " four "
play both ends to the middle
title = "Love"s Labours Lost" title.center 23 title.center 23, "-"
use center to create a comment:
filename = "hack.rb" # => "hack.rb" filename.size # => 7 filename.center 40-7, "#" # => "#############hack.rb#############"