class WebMock::Util::HashCounter
Attributes
Public Class Methods
Source
# File lib/webmock/util/hash_counter.rb, line 10 def initialize self.hash = Hash.new(0) @order = {} @max = 0 @lock = ::Mutex.new end
Public Instance Methods
Source
# File lib/webmock/util/hash_counter.rb, line 38 def each(&block) @order.to_a.sort_by { |a| a[1] }.each do |a| yield(a[0], hash[a[0]]) end end
Source
# File lib/webmock/util/hash_counter.rb, line 24 def get(key) @lock.synchronize do hash[key] end end
Source
# File lib/webmock/util/hash_counter.rb, line 17 def put(key, num=1) @lock.synchronize do hash[key] += num @order[key] = @max += 1 end end
Source
# File lib/webmock/util/hash_counter.rb, line 30 def select(&block) return unless block_given? @lock.synchronize do hash.select(&block) end end