Skip to content

Instantly share code, notes, and snippets.

@jaredatron
Created May 13, 2009 00:35
Show Gist options
  • Select an option

  • Save jaredatron/110810 to your computer and use it in GitHub Desktop.

Select an option

Save jaredatron/110810 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'blankslate'
# This wraps and object and controlls all the method calls sent to it
# in Object#__called__
class MethodSendRecorder < BlankSlate
def initialize(host)
@__host__ = host
@__called__ = []
end
attr_reader :__host__, :__called__
def __called?(method)
__called__.include? method.to_sym
end
def method_missing(method, *args, &block)
__called__ << method
__host__.send(method, *args, &block)
end
end
a = MethodSendRecorder.new( [1,2,3] )
puts a.reverse
puts a.__called? :reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment