instance method
String#rjust
(::int size, ?::string pad_string) -> ::String
rjust(width, pad_string = ' ') → new_string
string.c
View on GitHub ↗
static VALUE
rb_str_rjust(int argc, VALUE *argv, VALUE str)
{
return rb_str_justify(argc, argv, str, 'r');
}
Returns a right-justified copy of self.
If integer argument width is greater than the size (in characters) of self, returns a new string of length width that is a copy of self, right justified and padded on the left with pad_string:
Example
'hello'.rjust(10) # => " hello" 'hello '.rjust(10) # => " hello " 'hello'.rjust(10, 'ab') # => "ababahello" 'тест'.rjust(10) # => " тест" 'こんにちは'.rjust(10) # => " こんにちは"
If width <= self.size, returns a copy of self:
Example
'hello'.rjust(5, 'ab') # => "hello" 'hello'.rjust(1, 'ab') # => "hello"
Related: see Converting to New String.
Ruby version changes
-
3.0
-
The following methods now return or yield
Stringinstances instead of subclass instances when called on subclass instances: [Bug #10845]
-