class Ior
include Comparable
attr_reader :tail
def initialize(tail: true)
raise TypeError.new 'Ior expected a Boolean value' unless !!tail == tail
@tail = tail
end
def <=>(other) = (@tail ? 1 : 0 <=> other.tail ? 1 : 0)
def to_s = ('This one has %s tail' % [@tail ? 'a' : 'no'])
end
donkey1 = Ior.new
puts donkey1 # => This one has a tail
donkey2 = Ior.new(tail: false)
puts donkey2 # => This one has no tail
# a donkey with tail is greater than one without
puts donkey1 > donkey2 # => true
puts donkey1 == donkey2 # => false
donkey3 = Ior.new(tail: 2) # two tails!
# => Ior expected a Boolean value (TypeError)