Skip to content

Commit

Permalink
As suggested by alloy in http://is.gd/hEZA, changed some metaclass.cl…
Browse files Browse the repository at this point in the history
…ass_eval's to metaclass.send's. Definitely looks simpler and clearer.
  • Loading branch information
floehopper committed Jan 29, 2009
1 parent 911d458 commit 130d281
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/mocha/class_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def mock
def hide_original_method
if method_exists?(method)
begin
stubbee.__metaclass__.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
stubbee.__metaclass__.send(:alias_method, hidden_method, method)
rescue NameError
# deal with nasties like ActiveRecord::Associations::AssociationProxy
end
Expand All @@ -41,13 +41,14 @@ def define_new_method
end

def remove_new_method
stubbee.__metaclass__.class_eval("remove_method :#{method}", __FILE__, __LINE__)
stubbee.__metaclass__.send(:remove_method, method)
end

def restore_original_method
if method_exists?(hidden_method)
begin
stubbee.__metaclass__.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
stubbee.__metaclass__.send(:alias_method, method, hidden_method)
stubbee.__metaclass__.send(:remove_method, hidden_method)
rescue NameError
# deal with nasties like ActiveRecord::Associations::AssociationProxy
end
Expand Down

0 comments on commit 130d281

Please sign in to comment.