ruby - Command `left`, `right`, and `justify` -
line_width = 40 str = 'test' puts (str.ljust(line_width)) puts (str.rjust(line_width)) puts (str.center(line_width)) puts (str.ljust(line_width)) + (str.rjust(line_width))
output
test test test test test
both fourth line:
puts (str.rjust(line_width))
and sixth line
puts (str.rjust(line_width))
have same value 40
. why printed in different locations?
it's more obvious if specify "pad-string":
puts 'test'.ljust(40, '<') puts 'test'.rjust(40, '>') puts 'test'.center(40, '-') puts 'test'.ljust(40, '<') + 'test'.rjust(40, '>')
output:
test<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test ------------------test------------------ test<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>test
Comments
Post a Comment