Skip to content
This repository

Spira::Base should be comparable #24

bendiken opened this Issue September 15, 2010 · 4 comments

2 participants

Arto Bendiken Ben Lavender
Arto Bendiken

Currently, trying to sort a set or array of Spira resources results in the error:

undefined method `<=>' for #<MyClass:0x1020aa638>

To make this work, Spira::Base ought to mix in Comparable and implement a default #<=> method. An example implementation follows:

class Spira::Base
  include Comparable
  # @param  [Spira::Resource] other
  # @return [Integer]
  # @see
  def <=>(other)
    subject <=> other.subject

This guarantees that there is at least always some reasonable default ordering available (namely, that of the resource identifiers the instances represent), which users can override in their own Spira model class implementations should they ever need to.

Ben Lavender

Just waking up and haven't thought this through, but is this appropriate when considering that subjects can be Nodes? What are you doing, exactly?

Arto Bendiken

Anything that mixes in RDF::Value is comparable, so it doesn't matter whether subjects are URIs or blank nodes.

Arto Bendiken

Not sure if you closed this by accident or on purpose, but I still think this one-line method ought to be a part of Spira directly out of the shrinkwrap ;-)

Ben Lavender

I did indeed close it accidentally and thusly forgot about it. I will go ahead and add this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.