From: Peter Vanbroekhoven Date: 2005-10-18T09:15:09+09:00 Subject: Integer#** weirdness Hello, I've encountered a bit of a problem when I was trying out Ruby's numeric coercion: class SomeNumberLikeThing attr :value def initialize(value) @value = value end def **(other) SomeNumberLikeThing.new(value ** other.value) end def coerce(other) [SomeNumberLikeThing.new(other), self] end end p 2.0 ** SomeNumberLikeThing.new(2) # OK, returns # p 2 ** SomeNumberLikeThing.new(2) # ERROR: /home/peterv/local/lib/ruby/1.8/rational.rb:339:in `**': undefined method `>=' for # (NoMethodError) Seems that Integer#** tries to compare its argument to zero before coercing. Problem is that I don't want this SomeNumberLikeThing to be comparable. This is not something very exotic, as not all "number-like" things are (totally) ordered, e.g., polynomials, matrices and complex numbers. So IMO Integer#** should coerce before doing anything else with its argument. As a side note, Complex#<=> is defined, but it violates the definition of an order: Complex(1, 1) >= Complex(1, -1) and Complex(1, 1) <= Complex(1, -1) but not Complex(1, 1) == Complex(1, -1), which is a violation of the antisymmetry law. Peter