Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
sort Array of Hashes
Adgar Marks
7/27/2008 2:43:00 AM
Hi all,
i wrote array of hashes and i would like to sort it. I search in the net
few hours how to do this, but was not able to find exactly what i
wanted.
Here is my code:
_FilesData = Array.new
_FilesData << { :FileName => splitLine[8] ,
:Year => Time.now.year ,
:Month => month ,
:Day => splitLine[6].to_i ,
:Hour => hm[0].to_i ,
:Min => hm[1].to_i ,
:Suffix => Str ;
:Size => splitLine[4].to_i
}
I would like to sort _FilesData accourding to Year, then Month, then
Day, then by Suffix (Year, Month and Day are Integers numbers and Suffix
is an ascii string).
Just a remark, the size of _FilesData is more then one date set.
Thanks
--
Posted via
http://www.ruby-...
.
1 Answer
David A. Black
7/27/2008 2:52:00 AM
0
Hi --
On Sun, 27 Jul 2008, Adgar Marks wrote:
> Hi all,
>
> i wrote array of hashes and i would like to sort it. I search in the net
> few hours how to do this, but was not able to find exactly what i
> wanted.
>
> Here is my code:
> _FilesData = Array.new
_FilesData is kind of a weird variable name.
> _FilesData << { :FileName => splitLine[8] ,
> :Year => Time.now.year ,
> :Month => month ,
> :Day => splitLine[6].to_i ,
> :Hour => hm[0].to_i ,
> :Min => hm[1].to_i ,
> :Suffix => Str ;
> :Size => splitLine[4].to_i
> }
>
> I would like to sort _FilesData accourding to Year, then Month, then
> Day, then by Suffix (Year, Month and Day are Integers numbers and Suffix
> is an ascii string).
>
> Just a remark, the size of _FilesData is more then one date set.
Try this (untested):
_FilesData.sort_by {|hash| hash.values_at(:Year, :Month, :Day, :Suffix) }
David
--
Rails training from David A. Black and Ruby Power and Light:
* Advancing With Rails August 18-21 Edison, NJ
* Co-taught by D.A. Black and Erik Kastner
See
http://www.r...
for details and updates!
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
sort Array of Hashes
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password