Is there a method in Ruby that does the opposite String#succ
?
If you run succ
or next
you get this:
a = "4.4.10"
a.succ
=> "4.4.11"
I want the opposite:
a = "4.4.10"
a.previous
=> "4.4.09"
Is this possible? I was having a hard time finding this in the Ruby docs. Maybe it doesn't exist?
prev
or something similar is not in the standard API because succ
and a hypoethetical prev
are surjective. Despite this, "Implement Ruby String Class Prev / Pred / Prev! / Pred! - Opposite Of Next / Succ Methods" is a possible version you could use.
The root problem is that succ
is not inversible. This means, once you applied succ
, then prev
would end up with some ambiguity.
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