Priority Queue implementation for top k frequent elements leetcode in Ruby
The objects in the priority queue (as implemented above) have their priority determined by &lt;, &gt;, and ==. So however equality is defined for the object determines its priority. For numbers and strings, this is fairly obvious but the default implementation of equality, less than and greater than for hashes may surprise you and not give the result you are expecting.
Perhaps you could consider passing in a block to your initialize method to allow you to provide your own comparison function in those cases where the default one doesn't match your needs. Like Enumerable::sort does.