Skip to content

Comparison fails due to improper return value for <=> #38

@mateomurphy

Description

@mateomurphy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions