Ruby rpartition vs partition?

What is the difference between rpartition and partition? I read the documentation, but I see them the same. Is it just that they appeared in a later version of Ruby?

+4
source share
1 answer

The following example will help determine the difference:

"abccba".partition("b")
# => ["a", "b", "ccba"]

"abccba".rpartition("b")
# => ["abcc", "b", "a"]

Thus, the difference is that it rpartitionsearches for the rightmost entry, and not the leftmost.

+7
source

All Articles