[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

arity of methods defined with define_method

Paul Brannan

11/27/2003 2:52:00 PM

Why do I get the following arities:

irb(main):005:0> [pbrannan@zaphod tmp]$ irb
irb(main):001:0> RUBY_VERSION
=> "1.6.8"
irb(main):002:0> class Foo; define_method :foo, proc {}; end
=> #<Proc:0x402629e8>
irb(main):003:0> Foo.instance_method(:foo).arity
=> -135401849
irb(main):004:0>

[pbrannan@zaphod tmp]$ irb-1.8
irb(main):001:0> RUBY_VERSION
=> "1.8.1"
irb(main):002:0> class Foo; define_method :foo, proc {}; end
=> #<Proc:0x00000000@(irb):2>
irb(main):003:0> Foo.instance_method(:foo).arity
=> 1

In the first case I get a completely unexpected arity; I suspect this is
a bug that was fixed in 1.8?

In the second I get an arity of 1, but I can clearly call the method
with 0 or 3 arguments:

irb(main):004:0> Foo.new.foo()
=> nil
irb(main):005:0> Foo.new.foo(1, 2, 3)
=> nil

I would expect that a method that can take any number of arguments would
have an arity of -1. Why is this not the case with methods defined with
define_method()?

Paul



2 Answers

nobu.nokada

11/27/2003 4:11:00 PM

0

Hi,

At Thu, 27 Nov 2003 23:52:08 +0900,
Paul Brannan wrote:
> I would expect that a method that can take any number of arguments would
> have an arity of -1. Why is this not the case with methods defined with
> define_method()?

It's a bug.

* eval.c (method_arity): used wrong Proc object. [ruby-talk:86504]


Index: eval.c
===================================================================
RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.597
diff -u -2 -p -r1.597 eval.c
--- eval.c 27 Nov 2003 15:47:33 -0000 1.597
+++ eval.c 27 Nov 2003 16:06:46 -0000
@@ -7602,5 +7602,5 @@ method_arity(method)
case NODE_BMETHOD:
case NODE_DMETHOD:
- return proc_arity(method);
+ return proc_arity(body->nd_cval);
default:
body = body->nd_next; /* skip NODE_SCOPE */


--
Nobu Nakada


matz

11/27/2003 5:42:00 PM

0

Hi,

In message "Re: arity of methods defined with define_method"
on 03/11/28, nobu.nokada@softhome.net <nobu.nokada@softhome.net> writes:

|> I would expect that a method that can take any number of arguments would
|> have an arity of -1. Why is this not the case with methods defined with
|> define_method()?
|
|It's a bug.
|
|* eval.c (method_arity): used wrong Proc object. [ruby-talk:86504]

Please commit.

matz.