I want to define a constant FOO
in the namespace of Integer
that is similar to Float::NAN
in Float
, which is itself an instance of Float
. It will be used somewhat similar to symbols, i.e., to mark a special case (of an integer). I don't need it to be used in calculation, but I need it to have the following properties:
Its class must be
Integer
or a subclass ofInteger
, and it must behave so to methods related to class:Integer::FOO.kind_of?(Integer) # => true
Optionally (if the class is
Integer
):Integer::FOO.class # => Integer Integer === Integer::FOO # => true Integer::FOO.instance_of?(Integer) # => true
It must be distinct from (ideally all) other integers:
Integer::FOO == 0 # => false
Ideally, I want it distinct from any other integer, but if that is not possible, I can live with a dirty hack that, say makes
Integer::FOO
be identical to the largest or the smallest integer, which are the least likely to hit any random given integer.
What is the best way to go about this?