Spira::Base should be comparable #24

Closed
bendiken opened this Issue Sep 15, 2010 · 5 comments

Projects

None yet

2 participants

@bendiken
Datagraph, Inc. member

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    http://ruby-doc.org/core/classes/Comparable.html
  def <=>(other)
    subject <=> other.subject
  end
end

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.

@bhuga

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?

@bendiken
Datagraph, Inc. member

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

@bendiken
Datagraph, Inc. member

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 ;-)

@bhuga

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

@bendiken
Datagraph, Inc. member

This project has moved to ruby-rdf/spira. If this issue is still relevant, please resubmit it over there.

@bendiken bendiken closed this Aug 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment