Skip to content

Commit 5c683bd

Browse files
[DOC] Tweaks for String#succ
1 parent 7690309 commit 5c683bd

2 files changed

Lines changed: 54 additions & 51 deletions

File tree

doc/string/succ.rdoc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Returns the successor to +self+. The successor is calculated by
2+
incrementing characters.
3+
4+
The first character to be incremented is the rightmost alphanumeric:
5+
or, if no alphanumerics, the rightmost character:
6+
7+
'THX1138'.succ # => "THX1139"
8+
'<<koala>>'.succ # => "<<koalb>>"
9+
'***'.succ # => '**+'
10+
'тест'.succ # => "тесу"
11+
'こんにちは'.succ # => "こんにちば"
12+
13+
The successor to a digit is another digit, "carrying" to the next-left
14+
character for a "rollover" from 9 to 0, and prepending another digit
15+
if necessary:
16+
17+
'00'.succ # => "01"
18+
'09'.succ # => "10"
19+
'99'.succ # => "100"
20+
21+
The successor to a letter is another letter of the same case,
22+
carrying to the next-left character for a rollover,
23+
and prepending another same-case letter if necessary:
24+
25+
'aa'.succ # => "ab"
26+
'az'.succ # => "ba"
27+
'zz'.succ # => "aaa"
28+
'AA'.succ # => "AB"
29+
'AZ'.succ # => "BA"
30+
'ZZ'.succ # => "AAA"
31+
32+
The successor to a non-alphanumeric character is the next character
33+
in the underlying character set's collating sequence,
34+
carrying to the next-left character for a rollover,
35+
and prepending another character if necessary:
36+
37+
s = 0.chr * 3 # => "\x00\x00\x00"
38+
s.succ # => "\x00\x00\x01"
39+
s = 255.chr * 3 # => "\xFF\xFF\xFF"
40+
s.succ # => "\x01\x00\x00\x00"
41+
42+
Carrying can occur between and among mixtures of alphanumeric characters:
43+
44+
s = 'zz99zz99' # => "zz99zz99"
45+
s.succ # => "aaa00aa00"
46+
s = '99zz99zz' # => "99zz99zz"
47+
s.succ # => "100aa00aa"
48+
49+
The successor to an empty +String+ is a new empty +String+:
50+
51+
''.succ # => ""
52+
53+
Related: see {Converting to New String}[rdoc-ref:String@Converting+to+New+String].

string.c

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5315,57 +5315,7 @@ static VALUE str_succ(VALUE str);
53155315
* call-seq:
53165316
* succ -> new_str
53175317
*
5318-
* Returns the successor to +self+. The successor is calculated by
5319-
* incrementing characters.
5320-
*
5321-
* The first character to be incremented is the rightmost alphanumeric:
5322-
* or, if no alphanumerics, the rightmost character:
5323-
*
5324-
* 'THX1138'.succ # => "THX1139"
5325-
* '<<koala>>'.succ # => "<<koalb>>"
5326-
* '***'.succ # => '**+'
5327-
*
5328-
* The successor to a digit is another digit, "carrying" to the next-left
5329-
* character for a "rollover" from 9 to 0, and prepending another digit
5330-
* if necessary:
5331-
*
5332-
* '00'.succ # => "01"
5333-
* '09'.succ # => "10"
5334-
* '99'.succ # => "100"
5335-
*
5336-
* The successor to a letter is another letter of the same case,
5337-
* carrying to the next-left character for a rollover,
5338-
* and prepending another same-case letter if necessary:
5339-
*
5340-
* 'aa'.succ # => "ab"
5341-
* 'az'.succ # => "ba"
5342-
* 'zz'.succ # => "aaa"
5343-
* 'AA'.succ # => "AB"
5344-
* 'AZ'.succ # => "BA"
5345-
* 'ZZ'.succ # => "AAA"
5346-
*
5347-
* The successor to a non-alphanumeric character is the next character
5348-
* in the underlying character set's collating sequence,
5349-
* carrying to the next-left character for a rollover,
5350-
* and prepending another character if necessary:
5351-
*
5352-
* s = 0.chr * 3
5353-
* s # => "\x00\x00\x00"
5354-
* s.succ # => "\x00\x00\x01"
5355-
* s = 255.chr * 3
5356-
* s # => "\xFF\xFF\xFF"
5357-
* s.succ # => "\x01\x00\x00\x00"
5358-
*
5359-
* Carrying can occur between and among mixtures of alphanumeric characters:
5360-
*
5361-
* s = 'zz99zz99'
5362-
* s.succ # => "aaa00aa00"
5363-
* s = '99zz99zz'
5364-
* s.succ # => "100aa00aa"
5365-
*
5366-
* The successor to an empty +String+ is a new empty +String+:
5367-
*
5368-
* ''.succ # => ""
5318+
* :include: doc/string/succ.rdoc
53695319
*
53705320
*/
53715321

0 commit comments

Comments
 (0)