Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#rjust

str.rjust(integer, padstr=' ') → new_str

If integer is greater than the length of str, returns a new String of length integer with str right justified and padded with padstr; otherwise, returns str.

Example
"hello".rjust(4)            #=> "hello"
"hello".rjust(20)           #=> "               hello"
"hello".rjust(20, '1234')   #=> "123412341234123hello"

Ruby version changes

  1. 3.0
See also #rindex #rpartition #reverse! #rstrip also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1