From: Bulat Ziganshin Date: 2002-09-25T16:51:05+09:00 Subject: constructing closures on the fly Hello ruby-talk, ok, that's my problem: i had large list of filenames (100k strings, for example) and need to quickly sort them based on constructed criterion. This criterion gived by user in form of string containing letters 'ensgi3', where each letter maps to expression, parameterized by filename, so: filenames.sort_files "en" must be equal to filenames.sort_by {|name| [ext(name), name(name)]} filenames.sort_files "ges" must be equal to filenames.sort_by {|name| [group(name), ext(name), size(name)]} and so on. Currently i use non-functional approach: def sort_files(crit) sort_by {|name| construct(crit,name)} end def construct(crit,name) arr = [] crit.each_byte {|c| case c when ?g then arr << group(name) .... end } arr end while faster approach will be: def sort_files(crit) sort_by convert_crit(crit) end Best regards, Bulat mailto:bulatz@integ.ru