-
-
Save eqbal/c509a81baa335c5ab2bb96e4fbd21e6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EntryStatus | |
include Comparable | |
class NotValidEntryStatus < StandardError; end | |
OPTIONS = { | |
weather: %w(Sunny Rainy Windy Dry), | |
landform: %w(Beach Cliff Desert Flat) | |
} | |
attr_reader :weather, :landform | |
def initialize(weather, landform) | |
@weather, @landform = weather, landform | |
end | |
def <=>(other) | |
weather == other.weather && landform == other.landform | |
end | |
end |
btw, thank you for the great article!
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
shouldn't the <=> method return a -1, 0, or 1 instead of
true
orfalse
?