liveBook · Manning

String incrementation

As explained in The Well-Grounded Rubyist, Fourth Edition

String incrementation is the operation of producing the next string in Ruby's alphanumeric successor ordering.

String incrementation produces the next string in Ruby’s alphanumeric successor ordering. Call succ, also available as next, to obtain that successor. section 8.1.5

Odometer-style succession

"a".succ returns "b", "abc".succ returns "abd", and "azz".succ returns "baa". The ordering favors familiar alphabetic progression: after "z" comes "aa", rather than the ASCII character "{". section 8.1.5

>> "a".succ
=> "b"
>> "abc".succ
=> "abd"
>> "azz".succ
=> "baa"

Try these irb-sized examples to compare ordinary incrementing with rollover across alphabetic positions. section 8.1.5

This operation is useful when a program needs batch-generated unique strings, such as sequential filenames. section 8.1.5

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains succ and next through examples, alphabetic ordering, and odometer-style rollover without detailing implementation internals.
Examples
Uses "a", "abc", and "azz" to demonstrate ordinary succession and alphabetic rollover.
What it assumes
Assumes familiarity with strings and method calls while clarifying Ruby's alphanumeric successor ordering.
What you can do after
Apply Ruby's succ or next methods to produce successive strings for generated identifiers and filenames.
How it connects
Connects string incrementation with string transformation, string methods, and batch-generated filenames.

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.