How to pass a custom comparator to “sort”?
Define your own <=>, and include Comparable. This is from the Comparable doc: class SizeMatters include Comparable attr :str def <=>(an_other) str.size <=> an_other.str.size end def initialize(str) @str = str end def inspect @str end end s1 = SizeMatters.new(“Z”) s2 = SizeMatters.new(“YY”) s3 = SizeMatters.new(“XXX”) s4 = SizeMatters.new(“WWWW”) s5 = SizeMatters.new(“VVVVV”) s1 < s2 #=> … Read more