class MethodCallCount

Constants

VERSION

Public Class Methods

enable(klass) click to toggle source
Calls superclass method
# File lib/method_call_count.rb, line 9
def self.enable(klass)
  return if @@initialized.include?(klass)
  @@initialized.push(klass)
  klass.prepend Module.new{
    (klass.instance_methods - klass.superclass.instance_methods - [:enable]).each do |method|
      define_method(method) do |*args|
        @called[method] = (@called[method] || 0) + 1
        super(*args)
      end
    end

    def initialize(*args)
      @called = Hash.new{|h, k| h[k] = 0}
      super(*args)
    end

    def times_called
      @called.dup
    end
  }
end
new(*args) click to toggle source
Calls superclass method
# File lib/method_call_count.rb, line 20
def initialize(*args)
  @called = Hash.new{|h, k| h[k] = 0}
  super(*args)
end

Public Instance Methods

times_called() click to toggle source
# File lib/method_call_count.rb, line 25
def times_called
  @called.dup
end