Skip to content
Permalink
Browse files

Merge pull request #716 from krekoten/kernel_methods

Kernel#methods
  • Loading branch information
alex committed May 20, 2013
2 parents 5d64b2b + b20c214 commit fc2527283b808ea05e0045cf5cce0ab7aa95dc90
Showing with 32 additions and 17 deletions.
  1. +0 −16 spec/tags/core/kernel/methods_tags.txt
  2. +6 −0 topaz/modules/kernel.py
  3. +12 −1 topaz/objects/classobject.py
  4. +14 −0 topaz/objects/moduleobject.py
@@ -1,18 +1,2 @@
fails:Kernel#methods returns singleton methods defined by obj.meth
fails:Kernel#methods returns singleton methods defined in 'class << self'
fails:Kernel#methods returns private singleton methods defined by obj.meth
fails:Kernel#methods returns singleton methods defined in 'class << self' when it follows 'private'
fails:Kernel#methods does not return private singleton methods defined in 'class << self'
fails:Kernel#methods returns the publicly accessible methods of the object
fails:Kernel#methods returns the publicly accessible methods in the object, its ancestors and mixed-in modules
fails:Kernel#methods returns methods added to the metaclass through extend
fails:Kernel#methods does not return undefined singleton methods defined by obj.meth
fails:Kernel#methods does not return superclass methods undefined in the object's class
fails:Kernel#methods does not return superclass methods undefined in a superclass
fails:Kernel#methods does not return included module methods undefined in the object's class
fails:Kernel#methods when not passed an argument returns a unique list for an object extended by a module
fails:Kernel#methods when not passed an argument returns a unique list for a class including a module
fails:Kernel#methods when not passed an argument returns a unique list for a subclass of a class that includes a module
fails:Kernel#methods when passed true returns a unique list for an object extended by a module
fails:Kernel#methods when passed true returns a unique list for a class including a module
fails:Kernel#methods when passed true returns a unique list for a subclass of a class that includes a module
@@ -39,6 +39,12 @@ def method_singleton_methods(self, space, all=True):
w_cls = w_cls.superclass
return space.newarray([space.newsymbol(m) for m in methods])

@moduledef.method("methods", inherit="bool")
def method_methods(self, space, inherit=True):
w_cls = space.getclass(self)

return space.newarray([space.newsymbol(m) for m in w_cls.methods(space, inherit)])

@moduledef.method("lambda")
def function_lambda(self, space, block):
return block.copy(space, is_lambda=True)
@@ -1,7 +1,7 @@
import copy

from topaz.module import ClassDef
from topaz.objects.moduleobject import W_ModuleObject
from topaz.objects.moduleobject import UndefMethod, W_ModuleObject
from topaz.objects.objectobject import W_Object


@@ -74,6 +74,17 @@ def find_method_super(self, space, name):
method = self.superclass.find_method(space, name)
return method

def methods(self, space, inherit=True):
methods = {}
for name in W_ModuleObject.methods(self, space, inherit):
methods[name] = None
if inherit and self.superclass is not None:
for name in self.superclass.methods(space, inherit):
method = self._find_method_pure(space, name, self.version)
if method is None or not isinstance(method, UndefMethod):
methods[name] = None
return methods.keys()

def ancestors(self, include_singleton=True, include_self=True):
assert include_self
ary = W_ModuleObject.ancestors(self,
@@ -155,6 +155,20 @@ def find_method_super(self, space, name):
def _find_method_pure(self, space, method, version):
return self.methods_w.get(method, None)

def methods(self, space, inherit=True):
methods = {}
for name, method in self.methods_w.iteritems():
if not isinstance(method, UndefMethod):
methods[name] = None

if inherit:
for w_mod in self.included_modules:
for name in w_mod.methods(space, inherit):
method = self._find_method_pure(space, name, self.version)
if method is None or not isinstance(method, UndefMethod):
methods[name] = None
return methods.keys()

def set_const(self, space, name, w_obj):
self.mutated()
self.constants_w[name] = w_obj

0 comments on commit fc25272

Please sign in to comment.
You can’t perform that action at this time.