Skip to content

Commit

Permalink
Renamed Object#metaclass to Object#__metaclass__ to keep it out of th…
Browse files Browse the repository at this point in the history
…e way.
  • Loading branch information
floehopper committed Jan 11, 2007
1 parent a89c5ec commit 71d3e72
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/mocha/class_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ def mock
end

def hide_original_method
stubbee.metaclass.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.metaclass.method_defined?(method)
stubbee.__metaclass__.class_eval "alias_method :#{hidden_method}, :#{method}" if stubbee.__metaclass__.method_defined?(method)
end

def define_new_method
stubbee.metaclass.class_eval "def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end"
stubbee.__metaclass__.class_eval "def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end"
end

def remove_new_method
stubbee.metaclass.class_eval "remove_method :#{method}"
stubbee.__metaclass__.class_eval "remove_method :#{method}"
end

def restore_original_method
stubbee.metaclass.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.metaclass.method_defined?(hidden_method)
stubbee.__metaclass__.class_eval "alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}" if stubbee.__metaclass__.method_defined?(hidden_method)
end

def hidden_method
Expand Down
2 changes: 1 addition & 1 deletion lib/mocha/metaclass.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Object

def metaclass
def __metaclass__
class << self; self; end
end

Expand Down
4 changes: 2 additions & 2 deletions test/method_definer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Object

def define_instance_method(method_symbol, &block)
metaclass.send(:define_method, method_symbol, block)
__metaclass__.send(:define_method, method_symbol, block)
end

def replace_instance_method(method_symbol, &block)
Expand All @@ -12,7 +12,7 @@ def replace_instance_method(method_symbol, &block)
end

def define_instance_accessor(*symbols)
symbols.each { |symbol| metaclass.send(:attr_accessor, symbol) }
symbols.each { |symbol| __metaclass__.send(:attr_accessor, symbol) }
end

end

0 comments on commit 71d3e72

Please sign in to comment.