Created
May 13, 2009 00:35
-
-
Save jaredatron/110810 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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