String.ljust
Signature
string.ljust(length) #=> new_string
string.ljust(length, padding_string) #=> new_string
string.ljust(length) left justifies string to the given length. Iflength is greater than the length of string then a new string is returned
that is right padded to length with spaces, the default, or withpadding_string. If length is less than or equal to the length of string,
then string.ljust(length) returns a new string that is equal to string and
no padding or truncating occurs.
Examples
'foo'.ljust(10) #=> "foo "
'foo'.ljust(10,'x') #=> "fooxxxxxxx"
'foo'.ljust(2) #=> "foo"
'foo'.ljust(2,'x') #=> "foo"
Documentation Reference
- Log in to post comments
