What is the opposite of string.next?

前端 未结 1 1228
孤街浪徒
孤街浪徒 2020-12-03 01:28

Is there a method in Ruby that does the opposite String#succ?

If you run succ or next you get this:

a = \"4.4         


        
相关标签:
1条回答
  • 2020-12-03 01:44

    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.

    surjective map of succ and prev

    0 讨论(0)
提交回复
热议问题