Ruby Newbie homepage Ruby Newbie homepage

How to use

Quick guide

Official content
Centers str in width. If width is greater than the length of str, returns a new String of length width with str centered and padded with padstr; otherwise, returns str.
"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');

Was this page useful?