From: "Guy N. Hurst" Date: 2002-05-05T04:08:39+09:00 Subject: Object#pred One way to solve this whole issue is to define the set of values we wish to use #pred with. So, given a range from X to Y, a set of values is generated by #succ in a particular order. We can then use this resulting set or array as the determining factor when selecting the predecessor of a given element. Then, it will always be true that "aString.succ.pred = aString.pred.succ = aString". Here is a sample implementation which accepts either a range or some values to make a range from. It is valid for any object for which #succ is defined. class Object def pred(*args) if Range===args[0] arr=args[0].to_a else begin rng=((args[0])..(args[1])) rescue ArgumentError raise "Invalid Range Arguments" end arr=rng.to_a end if (pos=arr.index(self).to_i).zero? raise "Predecessor out of Range" end arr[pos-1] end end EXAMPLES: 5.pred(0..9) # 4 5.pred(0,9) # 4 -3.pred(-9,9) # -4 "d".pred("a".."z") # "c" "0".pred("\0","\255") # "/" "23".pred("\0","\255") # RuntimeError: Predecessor out of Range "23".pred("\0","\255\255") # "22" "2x3".pred("\0","\255\255\255") # RuntimeError: Predecessor out of Range "2x3".pred("0a0","9z9") # "2x2" class Class alias succ superclass end Numeric.pred(Fixnum..Object) # Fixnum (thanks Christoph ;-) Guy N. Hurst