diff --git a/doc/string/center.rdoc b/doc/string/center.rdoc index d53d921ad5..343f6ba263 100644 --- a/doc/string/center.rdoc +++ b/doc/string/center.rdoc @@ -2,15 +2,19 @@ Returns a centered copy of +self+. If integer argument +size+ is greater than the size (in characters) of +self+, returns a new string of length +size+ that is a copy of +self+, -centered and padded on both ends with +pad_string+: +centered and padded on one or both ends with +pad_string+: - 'hello'.center(10) # => " hello " - ' hello'.center(10) # => " hello " - 'hello'.center(10, 'ab') # => "abhelloaba" - 'тест'.center(10) # => " тест " - 'こんにちは'.center(10) # => " こんにちは " + 'hello'.center(6) # => "hello " # Padded on one end. + 'hello'.center(10) # => " hello " # Padded on both ends. + 'hello'.center(20, '-|') # => "-|-|-|-hello-|-|-|-|" # Some padding repeated. + 'hello'.center(10, 'abcdefg') # => "abhelloabc" # Some padding not used. + ' hello '.center(13) # => " hello " + 'тест'.center(10) # => " тест " + 'こんにちは'.center(10) # => " こんにちは " # Multi-byte characters. -If +size+ is not greater than the size of +self+, returns a copy of +self+: +If +size+ is less than or equal to the size of +self+, returns an unpadded copy of +self+: - 'hello'.center(5) # => "hello" - 'hello'.center(1) # => "hello" + 'hello'.center(5) # => "hello" + 'hello'.center(-10) # => "hello" + +Related: see {Converting to New String}[rdoc-ref:String@Converting+to+New+String]. diff --git a/string.c b/string.c index 33afa92a64..bc40fbbd34 100644 --- a/string.c +++ b/string.c @@ -11117,8 +11117,6 @@ rb_str_rjust(int argc, VALUE *argv, VALUE str) * * :include: doc/string/center.rdoc * - * Related: String#ljust, String#rjust. - * */ static VALUE diff --git a/string.rb b/string.rb index b02eeb4c88..617cccc782 100644 --- a/string.rb +++ b/string.rb @@ -443,7 +443,7 @@ # # - #*: Returns the concatenation of multiple copies of +self+. # - #+: Returns the concatenation of +self+ and a given other string. -# - #center: Returns a copy of +self+ centered between pad substrings. +# - #center: Returns a copy of +self+, centered by specified padding. # - #concat: Returns the concatenation of +self+ with given other strings. # - #prepend: Returns the concatenation of a given other string with +self+. # - #ljust: Returns a copy of +self+ of a given length, right-padded with a given other string.