Skip to content
Permalink
Browse files

Merge pull request #674 from krekoten/module_method_hooks

Module method_* hooks
  • Loading branch information
alex committed May 4, 2013
2 parents 43639ba + 7024721 commit c864124552015e4a3b9a7d10889636e2f6c41e89
@@ -1 +1,2 @@
fails:BasicObject#method_missing is a private method
fails:BasicObject#method_missing for a Class raises a NoMethodError when an undefined method is called
@@ -1,4 +1 @@
fails:BasicObject#singleton_method_added is a private method
fails:BasicObject#singleton_method_added is called when a method is defined on self
fails:BasicObject#singleton_method_added is called when a method is defined in the singleton class
fails:BasicObject#singleton_method_added is called when define_method is used in the singleton class
@@ -1,2 +1 @@
fails:BasicObject#singleton_method_undefined is a private method
fails:BasicObject#singleton_method_undefined is called when a method is removed on self
@@ -10,3 +10,7 @@ fails:Kernel#method_missing for an instance with #method_missing defined is call
fails:Kernel#method_missing for an instance with #method_missing defined is called when an private method is called
fails:Kernel#method_missing for an instance raises a NoMethodError when a protected method is called
fails:Kernel#method_missing for an instance raises a NoMethodError when a private method is called
fails:Kernel#method_missing for a Module with #method_missing defined is called when an undefined method is called
fails:Kernel#method_missing for a Module raises a NoMethodError when an undefined method is called
fails:Kernel#method_missing for a Class with #method_missing defined is called when an undefined method is called
fails:Kernel#method_missing for a Class raises a NoMethodError when an undefined method is called
@@ -1,3 +1 @@
fails:Module#method_added is a private instance method
fails:Module#method_added returns nil in the default implementation
fails:Module#method_added is called when a new method is defined in self
@@ -1,3 +1 @@
fails:Module#method_undefined is a private instance method
fails:Module#method_undefined returns nil in the default implementation
fails:Module#method_undefined is called when a method is undefined from self
@@ -25,6 +25,7 @@ def __init__(self, space, name, superclass, is_singleton=False, attached=None):
def __deepcopy__(self, memo):
obj = super(W_ClassObject, self).__deepcopy__(memo)
obj.is_singleton = self.is_singleton
obj.attached = copy.deepcopy(self.attached, memo)
obj.superclass = copy.deepcopy(self.superclass, memo)
return obj

@@ -81,6 +82,18 @@ def method_removed(self, space, w_name):
else:
W_ModuleObject.method_removed(self, space, w_name)

def method_added(self, space, w_name):
if self.is_singleton:
space.send(self.attached, space.newsymbol("singleton_method_added"), [w_name])
else:
W_ModuleObject.method_added(self, space, w_name)

def method_undefined(self, space, w_name):
if self.is_singleton:
space.send(self.attached, space.newsymbol("singleton_method_undefined"), [w_name])
else:
W_ModuleObject.method_undefined(self, space, w_name)

@classdef.singleton_method("allocate")
def singleton_method_allocate(self, space, w_superclass=None):
if w_superclass is not None:
@@ -131,6 +131,11 @@ def mutated(self):
def define_method(self, space, name, method):
self.mutated()
self.methods_w[name] = method
if not space.bootstrap:
if isinstance(method, UndefMethod):
self.method_undefined(space, space.newsymbol(name))
else:
self.method_added(space, space.newsymbol(name))

@jit.unroll_safe
def find_method(self, space, name):
@@ -301,6 +306,15 @@ def set_default_visibility(self, space, visibility):
def set_method_visibility(self, space, name, visibility):
pass

def method_added(self, space, w_name):
space.send(self, space.newsymbol("method_added"), [w_name])

def method_undefined(self, space, w_name):
space.send(self, space.newsymbol("method_undefined"), [w_name])

def method_removed(self, space, w_name):
space.send(self, space.newsymbol("method_removed"), [w_name])

@classdef.singleton_method("nesting")
def singleton_method_nesting(self, space):
frame = space.getexecutioncontext().gettoprubyframe()
@@ -627,8 +641,13 @@ def method_remove_method(self, space, name):
self.method_removed(space, space.newsymbol(name))
return self

def method_removed(self, space, w_name):
space.send(self, space.newsymbol("method_removed"), [w_name])
@classdef.method("method_added")
def method_method_added(self, space, w_name):
return space.w_nil

@classdef.method("method_undefined")
def method_method_undefined(self, space, w_name):
return space.w_nil

@classdef.method("method_removed")
def method_method_removed(self, space, w_name):
@@ -103,6 +103,13 @@ def method_instance_eval(self, space, string=None, filename=None, w_lineno=None,
def method_singleton_method_removed(self, space, w_name):
return space.w_nil

@classdef.method("singleton_method_added")
def method_singleton_method_added(self, space, w_name):
return space.w_nil

@classdef.method("singleton_method_undefined")
def method_singleton_method_undefined(self, space, w_name):
return space.w_nil

class W_RootObject(W_BaseObject):
_attrs_ = []

0 comments on commit c864124

Please sign in to comment.