Skip to content

Instantly share code, notes, and snippets.

@abriening
Created May 12, 2009 14:18
Show Gist options
  • Save abriening/110507 to your computer and use it in GitHub Desktop.
Save abriening/110507 to your computer and use it in GitHub Desktop.
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