Sha256: 00ed5bcb75f9fc68ca33b2281c906b186f9d308562be0cb90df3be05c4cccbb5
Contents?: true
Size: 618 Bytes
Versions: 2
Compression:
Stored size: 618 Bytes
Contents
module WebMock module Util class Util::HashCounter attr_accessor :hash def initialize self.hash = {} @order = {} @max = 0 @lock = Mutex.new end def put key, num=1 @lock.synchronize do hash[key] = (hash[key] || 0) + num @order[key] = @max = @max + 1 end end def get key @lock.synchronize do hash[key] || 0 end end def each(&block) @order.to_a.sort {|a, b| a[1] <=> b[1]}.each do |a| block.call(a[0], hash[a[0]]) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
webmock-1.9.2 | lib/webmock/util/hash_counter.rb |
webmock-1.9.1 | lib/webmock/util/hash_counter.rb |