Skip to content
Permalink
Browse files

Merge pull request #711 from kostya/proc_arity

Proc#arity
  • Loading branch information
alex committed May 18, 2013
2 parents f73e5ed + 433c4ea commit aabccc5c595b9ebca40d58bb2bec79e68871acd4
@@ -1,29 +1,5 @@
fails:Proc#arity
fails:Proc#arity returns 0 for a block taking no arguments
fails:Proc#arity returns 0 for a block taking || arguments
fails:Proc#arity returns 1 for a block taking |a| arguments
fails:Proc#arity returns 1 for a block taking |a, | arguments
fails:Proc#arity returns -2 for a block taking |a, *| arguments
fails:Proc#arity returns -2 for a block taking |a, *b| arguments
fails:Proc#arity returns -3 for a block taking |a, b, *c| arguments
fails:Proc#arity returns 2 for a block taking |a, b| arguments
fails:Proc#arity returns 3 for a block taking |a, b, c| arguments
fails:Proc#arity returns -1 for a block taking |*| arguments
fails:Proc#arity returns -1 for a block taking |*a| arguments
fails:Proc#arity returns 1 for a block taking |(a, b)| arguments
fails:Proc#arity returns 1 for a block taking |(a, *)| arguments
fails:Proc#arity returns 1 for a block taking |(a, *b)| arguments
fails:Proc#arity returns 2 for a block taking |a, (b, c)| arguments
fails:Proc#arity returns 2 for a block taking |a, (b, *c)| arguments
fails:Proc#arity returns 2 for a block taking |(a, b), c| arguments
fails:Proc#arity returns -2 for a block taking |(a, b), *c| arguments
fails:Proc#arity returns 2 for a block taking |(a, *b), c| arguments
fails:Proc#arity returns -1 for a block taking |a = 0, *b| argument
fails:Proc#arity returns -1 for a lambda taking one optional argument
fails:Proc#arity returns -2 for a lambda taking |a, b = 0| argument
fails:Proc#arity returns -2 for a lambda taking |a, b = 0, c = 0| argument
fails:Proc#arity returns -2 for a lambda taking |(a, b), c = 0| argument
fails:Proc#arity returns 0 for a Proc taking one optional argument
fails:Proc#arity returns 1 for a Proc taking |a, b = 0| argument
fails:Proc#arity returns 1 for a Proc taking |a, b = 0, c = 0| argument
fails:Proc#arity returns 1 for a Proc taking |(a, b), c = 0| argument
@@ -58,7 +58,6 @@ class MSpecScript
"^#{Rubyspec}/core/file/ftype_spec.rb",
"^#{Rubyspec}/core/file/open_spec.rb",
"^#{Rubyspec}/core/io/sysopen_spec.rb",
"^#{Rubyspec}/core/method/arity_spec.rb",
"^#{Rubyspec}/core/method/call_spec.rb",
"^#{Rubyspec}/core/method/clone_spec.rb",
"^#{Rubyspec}/core/method/element_reference_spec.rb",
@@ -58,6 +58,12 @@ def __deepcopy__(self, memo):
obj.splat_arg_pos = self.splat_arg_pos
return obj

def arity(self, negative_defaults=False):
args_count = len(self.arg_pos) - len(self.defaults)
if self.splat_arg_pos != -1 or (negative_defaults and len(self.defaults) > 0):
args_count = -(args_count + 1)
return args_count

@classdef.method("filepath")
def method_filepath(self, space):
return space.newstr_fromstr(self.filepath)
@@ -47,11 +47,7 @@ def call(self, space, w_receiver, args_w, block):
return space.execute_frame(frame, self.bytecode)

def arity(self, space):
args_count = len(self.bytecode.arg_pos) - len(self.bytecode.defaults)
if len(self.bytecode.defaults) > 0 or self.bytecode.splat_arg_pos != -1:
args_count = -(args_count + 1)

return space.newint(args_count)
return space.newint(self.bytecode.arity(negative_defaults=True))


class W_BuiltinFunction(W_FunctionObject):
@@ -64,11 +64,7 @@ def call(self, space, w_obj, args_w, block):
return e.w_value

def arity(self, space):
args_count = len(self.block.bytecode.arg_pos) - len(self.block.bytecode.defaults)
if len(self.block.bytecode.defaults) > 0 or self.block.bytecode.splat_arg_pos != -1:
args_count = -(args_count + 1)

return space.newint(args_count)
return space.newint(self.block.bytecode.arity(negative_defaults=True))


class DefineMethodMethod(W_FunctionObject):
@@ -58,6 +58,10 @@ def method_call(self, space, args_w, block):
def method_lambda(self, space):
return space.newbool(self.is_lambda)

@classdef.method("arity")
def method_arity(self, space):
return space.newint(self.bytecode.arity())

@classdef.method("binding")
def method_binding(self, space):
return space.newbinding_fromblock(self)

0 comments on commit aabccc5

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