At Wed, 25 Sep 2002 19:14:50 +0900,
GOTO Kentaro wrote:
>   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

Case statement can be replaced an hash (like Christian's [ruby-talk:51284]). 

  class Proc
    def *(other) Proc.new{|i| other.yield(self.yield(i))} end
  end

  CRITERIA_PROCS = {
    ?a => Proc.new{|i,a| [i, a << File.atime(i)]}, 
    ?c => Proc.new{|i,a| [i, a << File.ctime(i)]}, 
    ?e => Proc.new{|i,a| [i, a << File.extname(i)]}, 
    ?m => Proc.new{|i,a| [i, a << File.mtime(i)]}, 
    ?n => Proc.new{|i,a| [i, a << File.basename(i).sub(/\.([^.]+)$/, "")]}, 
    ?s => Proc.new{|i,a| [i, a << File.size(i)]}, 
    # and more
  }

  def criteria(opt, part = CRITERIA_PROCS)
    f = Proc.new{|i| [i, []]}
    opt.each_byte{|c| f *= part[c]}
    f * Proc.new{|i,a| a}
  end

  puts Dir["*"].sort_by(&criteria("esm"))

-- Gotoken