[DOC] Tweaks for String#center

This commit is contained in:
BurdetteLamar 2025-07-07 14:28:27 -05:00 committed by Peter Zhu
parent 9e4157a01c
commit 14971e75ce
3 changed files with 14 additions and 12 deletions

View file

@ -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].

View file

@ -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

View file

@ -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.