Permalink
Browse files

As suggested by alloy in http://is.gd/hEZA, changed some metaclass.cl…

…ass_eval's to metaclass.send's. Definitely looks simpler and clearer.
  • Loading branch information...
1 parent 911d458 commit 130d2815f70215fdd39912b93ec54d20e36d0086 @floehopper floehopper committed Jan 29, 2009
Showing with 4 additions and 3 deletions.
  1. +4 −3 lib/mocha/class_method.rb
View
7 lib/mocha/class_method.rb
@@ -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
@@ -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

0 comments on commit 130d281

Please sign in to comment.