Skip to content

Instantly share code, notes, and snippets.

@irisfofs
Created February 5, 2016 18:19
Show Gist options
  • Save irisfofs/34ca6f2c114501d6a205 to your computer and use it in GitHub Desktop.
Save irisfofs/34ca6f2c114501d6a205 to your computer and use it in GitHub Desktop.
Alternate Tag#<=> implementation
##
# Compares two tags. Character tags are less than meta tags, and meta
# tags are less than general tags. Two tags of the same type are compared
# by their names.
def <=>(other)
sort_order = [:character, :meta, :general]
arr = [""] * 3
other_arr = [""] * 3
# Due to quirks, the string <=> behavior vs "" is the opposite of what
# we want for comparing names. "" is the 'smallest' string. Everything
# is greater than it.
arr[sort_order.index type] = other.name
other_arr[sort_order.index other.type] = name
puts "#{arr.inspect} <=> #{other_arr.inspect}"
other_arr <=> arr
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment