From: Brian Candler Date: 2004-10-04T23:37:09+09:00 Subject: Re: Too Many Ways? On Mon, Oct 04, 2004 at 11:08:42PM +0900, trans. (T. Onoma) wrote: > Agreed. The reason I've gone the other way is b/c of this kind of thing: > > def ducky_method(a,b,c,d,e) > end > > ... > > case method(:ducky_method).arity > when 5 > when 4 > when 3 > ... Ugh... fortunately I've never had to write code like that :-) Especially with the nasty overloading of negative values: -3 means 2..infinity. (Or is it 4..infinity? I have to think about it every time. Remember, -1 means 0 to infinity, obviously. So -3 is 2 to infinity. Got that?) Anyway, I would hope that those methods would be declared as def ducky_method(a,b,c) def ducky_method(a,b,c,d=99) def ducky_method(a,b,c,d=99,e=123) and that you would therefore know that a call with 3 parameters makes sense. Otherwise, perhaps those methods should have completely different names, if they do different things altogether (i.e. if it has two legs it's a goose, if it has 4 legs it's a mongoose) > > I quite like your suggestion of &blk=nil though. At the moment in Ruby the > > presence/absence of a block makes no difference, until you try to 'yield' > > when no block is given. In particular, you can pass a block to a method > > which doesn't expect one; I've been caught by that before! > > Yes, I like it _better_ too. But like matz said it would break a good bit of > code :( Perhaps these things are up for grabs in 2.0 though. Regards, Brian.