Skip to content

Instantly share code, notes, and snippets.

Created December 6, 2016 13:22
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
class EntryStatus
include Comparable
class NotValidEntryStatus < StandardError; end
weather: %w(Sunny Rainy Windy Dry),
landform: %w(Beach Cliff Desert Flat)
attr_reader :weather, :landform
def initialize(weather, landform)
@weather, @landform = weather, landform
def <=>(other)
weather == && landform == other.landform
Copy link

jfnixon commented Dec 22, 2016

Yeah, you must implement <=> for Comparable, but there is no obvious sort order for EntryStatus instances to determine whether to return 1 or -1. If you try to sort EntryStatus instances, there might be problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment