ruby-duration icon indicating copy to clipboard operation
ruby-duration copied to clipboard

Comparison fails due to improper return value for <=>

Open mateomurphy opened this issue 10 months ago • 0 comments

The <=> should return nil if the objects are not comparable, but it currently returns false, which causes errors.

Also, checking against the existance of to_i would make things more flexible: e.g.

  # Compare this duration to another (or objects that respond to #to_i)
  def <=>(other)
    return nil unless other.respond_to?(:to_i)

    @total <=> other.to_i
  end

mateomurphy avatar Apr 01 '25 21:04 mateomurphy