From: Eric Mahurin Date: 2005-10-20T22:26:44+09:00 Subject: Re: Anonymous methods, blocks etc. (Cont. 'default block params') --- Trans wrote: > > Eric Mahurin wrote: > > --- Trans wrote: > > > > > > > > Austin Ziegler wrote: > > > > > > > > I'm not wanting to extrapolate. Consider me the > > > conservative here, > > > > Trans. Convince me that this is really useful and > > > important. > > > > > > It's all relative Austin. How *really useful and > important* > > > is > > > anything? Most things can be done in some other way. But > this > > > much is > > > certain, there are things you CAN'T do b/c of this --or > at > > > least not > > > wihtout jumping through some magical hoops like defining > a > > > method > > > grabing the UnboundMethod, converting to_proc and > undefining > > > the method > > > (which I have done). But as to the example I was trying > to > > > show here... > > > here's something a little bit more real-to-life, though > still > > > off the > > > top of my head. > > > > > > dir = File.dirname(__FILE__) > > > > > > m = module.new do > > > > > > make_dir_method = lambda { |which, path| > > > class_eval { > > > define_method( "#{which}dir" ) { |name| > > > dir = File.dirname(path) > > > name = File.basename(path) > > > File.join(dir,which,name) > > > } > > > } > > > } > > > > > > make_dir_method('lib',dir) > > > make_dir_method('var',dir) > > > make_dir_method('bin',dir) > > > > > > end > > > > Trans, I thought the discussion was the need for a > non-closure > > block/lambda. The above has very little to do with closure > > blocks/lambdas vs. non-closure blocks/lambdas. All you're > > asking for in the above is for a ()-like operator that > > correlates to #call. I too would like that especially when > the > > lambda takes a block (only in v1.9). When it doesn't take > a > > block, you can easily get similar syntax by using the [] > > operator on a Proc: > > No no. That was actually just a mistype (well it works in an > old 1.9 > version, but) it's not the point at all. Then what was your point of the above code? All 3 of the blocks above need to be closures. The inner block references dir which is defined in the outer-most scope. I thought you were trying to convince the need of a non-closure. __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com