Skip to content

Commit 14971e7

Browse files
BurdetteLamarpeterzhu2118
authored andcommitted
[DOC] Tweaks for String#center
1 parent 9e4157a commit 14971e7

3 files changed

Lines changed: 14 additions & 12 deletions

File tree

doc/string/center.rdoc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ Returns a centered copy of +self+.
22

33
If integer argument +size+ is greater than the size (in characters) of +self+,
44
returns a new string of length +size+ that is a copy of +self+,
5-
centered and padded on both ends with +pad_string+:
5+
centered and padded on one or both ends with +pad_string+:
66

7-
'hello'.center(10) # => " hello "
8-
' hello'.center(10) # => " hello "
9-
'hello'.center(10, 'ab') # => "abhelloaba"
10-
'тест'.center(10) # => " тест "
11-
'こんにちは'.center(10) # => " こんにちは "
7+
'hello'.center(6) # => "hello " # Padded on one end.
8+
'hello'.center(10) # => " hello " # Padded on both ends.
9+
'hello'.center(20, '-|') # => "-|-|-|-hello-|-|-|-|" # Some padding repeated.
10+
'hello'.center(10, 'abcdefg') # => "abhelloabc" # Some padding not used.
11+
' hello '.center(13) # => " hello "
12+
'тест'.center(10) # => " тест "
13+
'こんにちは'.center(10) # => " こんにちは " # Multi-byte characters.
1214

13-
If +size+ is not greater than the size of +self+, returns a copy of +self+:
15+
If +size+ is less than or equal to the size of +self+, returns an unpadded copy of +self+:
1416

15-
'hello'.center(5) # => "hello"
16-
'hello'.center(1) # => "hello"
17+
'hello'.center(5) # => "hello"
18+
'hello'.center(-10) # => "hello"
19+
20+
Related: see {Converting to New String}[rdoc-ref:String@Converting+to+New+String].

string.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11117,8 +11117,6 @@ rb_str_rjust(int argc, VALUE *argv, VALUE str)
1111711117
*
1111811118
* :include: doc/string/center.rdoc
1111911119
*
11120-
* Related: String#ljust, String#rjust.
11121-
*
1112211120
*/
1112311121

1112411122
static VALUE

string.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@
443443
#
444444
# - #*: Returns the concatenation of multiple copies of +self+.
445445
# - #+: Returns the concatenation of +self+ and a given other string.
446-
# - #center: Returns a copy of +self+ centered between pad substrings.
446+
# - #center: Returns a copy of +self+, centered by specified padding.
447447
# - #concat: Returns the concatenation of +self+ with given other strings.
448448
# - #prepend: Returns the concatenation of a given other string with +self+.
449449
# - #ljust: Returns a copy of +self+ of a given length, right-padded with a given other string.

0 commit comments

Comments
 (0)