What is the difference between rpartition and partition? I have read the documentation but I see them like the same. Is it just that ones came up in a later ruby version?
The following example will help identify the difference:
"abccba".partition("b")
# => ["a", "b", "ccba"]
"abccba".rpartition("b")
# => ["abcc", "b", "a"]
So the difference is that rpartition
searches for the rightmost occurrence, instead of the leftmost one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With