From: Eric Mahurin Date: 2005-06-29T06:56:39+09:00 Subject: Re: yield does not take a block --- Jim Freeze wrote: > * Ryan Leavengood [2005-06-29 05:49:45 > +0900]: > > > I like yield as a keyword, and I think the only reason to > use &block is > > when you want to save the given block or do some other > manipulation on it > > (ask for its arity, etc.) It is a lot of extra typing to > use an &block > > parameter than just calling yield, especially if all you > want to do is > > yield a value. Conceptually I think the idea of 'yield'ing > control to a > > block is nice (though I suppose the idea of 'call'ing a > block is just as > > nice.) But I still don't think yield should be tossed (not > that matz ever > > would.) > > The implicit passing of a block (that follows a method call) > and > the 'yield' keyword is one of the key signatures of Ruby and > one > that gives Ruby a great deal of power with very little > typing. > > If we had the principle of absolute explicitness for > everything, > then it would be more difficult to write DSL's and we > wouldn't > have nice apps like rails. In fact, we would probably even > have > to add statement ending identifiers, like semicolons....run > away run away... I really like the block passing thing in ruby too. I also think it to be one of the most distinguishing features over many other languages. What I don't like from the method definition perspective, is that you have no control over whether the block is not allowed, optional, or required. I would have liked being able to define my methods like this to control it: def block_prohibited(*args) ... end def block_allowed(*args,&block=nil) ... block.call(...) if block ... end def block_required(*args,&block) ... block.call(...) ... end Of course these (at least the first and last) break compatibility, so this ain't gonna happen. But, this would make sense relative the way other args are defined and assigned default values. ____________________________________________________ Yahoo! Sports Rekindle the Rivalries. Sign up for Fantasy Football http://football.fantasysports.yahoo.com