Created
May 12, 2009 14:18
-
-
Save abriening/110507 to your computer and use it in GitHub Desktop.
This file contains 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
class ProcMatcher | |
attr_accessor :proc, :calls, :args | |
def initialize(proc) | |
@proc = proc | |
@calls = [] | |
@args = [] | |
end | |
def parse | |
@calls = [] | |
@args = [] | |
num = @proc.arity | |
new_args = [] | |
num.times{ new_args << self } | |
@proc.call *new_args | |
end | |
def method_missing(m,*args,&block) | |
# any blocks inside of the proc body are ignored ... for now | |
@calls << m | |
@args << args | |
self | |
end | |
def match(other_proc) | |
other_matcher = new other_proc | |
parse | |
other_matcher.parse | |
calls == other_matcher.calls && args == other_matcher.args | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment