class WebMock::Util::WebMock::Util::Util::HashCounter
Attributes
hash[RW]
Public Class Methods
new()
click to toggle source
# File lib/webmock/util/hash_counter.rb, line 7 def initialize self.hash = {} @order = {} @max = 0 @lock = ::Mutex.new end
Public Instance Methods
each(&block)
click to toggle source
# File lib/webmock/util/hash_counter.rb, line 25 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
get(key)
click to toggle source
# File lib/webmock/util/hash_counter.rb, line 19 def get key @lock.synchronize do hash[key] || 0 end end
put(key, num=1)
click to toggle source
# File lib/webmock/util/hash_counter.rb, line 13 def put key, num=1 @lock.synchronize do hash[key] = (hash[key] || 0) + num @order[key] = @max = @max + 1 end end