汎用の最大値・最小値
ruby-list にも流してみたもの
coerce がミソ
class Sentinel include Comparable MAX = new def MAX.<=> other 1 end def MAX.coerce other [MIN, self] end MIN = new def MIN.<=> other -1 end def MIN.coerce other [MAX, self] end private def self.new end end
ruby-list にも流してみたもの
coerce がミソ
class Sentinel include Comparable MAX = new def MAX.<=> other 1 end def MAX.coerce other [MIN, self] end MIN = new def MIN.<=> other -1 end def MIN.coerce other [MAX, self] end private def self.new end end