From: GOTO Kentaro Date: 2002-09-25T19:14:50+09:00 Subject: Re: are functions/methods "first class objects"? At Wed, 25 Sep 2002 15:59:02 +0900, Bulat Ziganshin wrote: > hmm. you don't understand. sort string is a sequence of chars, which > maps to sort criterions. this char may be oops. I didn't read context :< > e for extennsion > n for filename w/o path/extension > s for size > g for group (one group is c sources, next - executables and so on) > i for some intellectual THING :) > > i need to translate sequence of this chars to function which returns > array with all the data for sort_by: > > sort_files "es" > sort_files "en" > sort_files "geis" > > and much more variants. so i need to construct closure on the fly I see. A point seems how to pass a filename to each component... class Proc def *(other) lambda{|i| other.yield(self.yield(i))} end end F_Bootstrap = Proc.new{|i| [i, []]} F_SIZE = Proc.new{|i,a| [i, a << File.size(i)]} F_EXT = Proc.new{|i,a| [i, a << File.extname(i)]} F_Trailer = Proc.new{|i,a| a} def criteria(opt) f = F_Bootstrap opt.each_byte do |c| case c when ?s f *= F_SIZE when ?e f *= F_EXT end end f * F_Trailer end puts Dir["*"].sort_by(&criteria("se")) -- Gotoken