Skip to content

Commit

Permalink
Use define_method instead of class_eval & string.
Browse files Browse the repository at this point in the history
This will make it easier to introduce a check at invocation time which compares
the number of arguments passed into the stubbed method and the "arity" of the
original method implementation.
  • Loading branch information
floehopper committed Oct 27, 2013
1 parent 3c3ce76 commit bd9e1c8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/mocha/class_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ def hide_original_method
end

def define_new_method
stubbee.__metaclass__.class_eval(%{
def #{method}(*args, &block)
mocha.method_missing(:#{method}, *args, &block)
end
}, __FILE__, __LINE__)
class_method = self
stubbee.__metaclass__.send(:define_method, method) do |*args, &block|
mocha.method_missing(class_method.method, *args, &block)
end
if @original_visibility
Module.instance_method(@original_visibility).bind(stubbee.__metaclass__).call(method)
end
Expand Down

0 comments on commit bd9e1c8

Please sign in to comment.