This was throwing a `comparison of Hash with Hash failed` error for me, which seemed to indicate that some rule did not have a weight. Explicitly casting `to_i` will make undefined weights 0, which I guess could cause issues. It may be better to do something like `a[:weight]||50 <=> b[:weight]|||50` but I didn't test that.