From: Trans Date: 2005-10-20T14:21:59+09:00 Subject: Anonymous methods, blocks etc. (Cont. 'default block params') 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. Sorry, T.