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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -