----- Original Message ----- 
From: "Kontra, Gergely" <kgergely / mlabdial.hit.bme.hu>


> Hi!
> 
> I want to sort a number of File::Stat object due to the user's choice.
> [Anyway, can I read back the filename from the Stat object?]

No you cant.

> My idea was to build a hash, keys are 'name', 'size', ... and values are
> proc objects doing the comparism. Then I just can write.
> 
> userChoice='size'
> myArray.sort(sortMethods[userChoice])
> 
> But I don't know the correct syntax.
> I'm still using ruby1.6, if it matters.

Try this.

class Array
  def sort_by(method)
    self.sort { |a,b| a.send(method) <=> b.send(method) }
  end
end

user_choice = 'size'
array.sort_by(user_choice)

I believe sort_by is introduced in 1.7.

> +-[Kontra, Gergely @ Budapest University of Technology and Economics]-+

Gavin