VOOZH about

URL: https://apidock.com/ruby/String/center

⇱ String#center - APIdock


method

center

ruby latest stable - Class: String
center(*args)
public

Centers in . If is greater than the length of returns a new String of length with centered and padded with ; otherwise, returns .

"hello".center(4) #=> "hello"
"hello".center(20) #=> " hello "
"hello".center(20, '123') #=> "1231231hello12312312"
static VALUE
rb_str_center(int argc, VALUE *argv, VALUE str)
{
 return rb_str_justify(argc, argv, str, 'c');
}

Related methods