How does one sort it first by the name value, then by the sort_date
value? (So that the name == 'goober' items appear before the others,
and the very first element returned by the sort would be @my_hash[8858]?)
I tried searching a bit (the FAQ and google) , but came up empty; sorry
if this is a noob question. (Although, I am a ruby noob, so...)
sorted_keys = @my_hash.keys.sort do |a,b|
next result unless res=(@my_hash[a]['name']<=>@my_hash[b]['name']) == 0 @my_hash[a]['sort_date']<=>@my_hash[b]['sort_date']
end
Then since you have your sorted keys you can iterate over each item based on your sorted_keys array.
How does one sort it first by the name value, then by the sort_date
value? (So that the name == 'goober' items appear before the others,
and the very first element returned by the sort would be @my_hash[8858]?)
I tried searching a bit (the FAQ and google) , but came up empty; sorry
if this is a noob question. (Although, I am a ruby noob, so...)
How does one sort it first by the name value, then by the sort_date
value? (So that the name == 'goober' items appear before the others,
and the very first element returned by the sort would be @my_hash[8858]?)
I tried searching a bit (the FAQ and google) , but came up empty; sorry
if this is a noob question. (Although, I am a ruby noob, so...)
How does one sort it first by the name value, then by the sort_date
value? (So that the name == 'goober' items appear before the others,
and the very first element returned by the sort would be @my_hash[8858]?)
I tried searching a bit (the FAQ and google) , but came up empty; sorry
if this is a noob question. (Although, I am a ruby noob, so...)
There is probably a cleaner way to do this but...
sorted_keys = @my_hash.keys.sort do |a,b|
next result unless res=(@my_hash[a]['name']<=>@my_hash[b]['name']) == 0 @my_hash[a]['sort_date']<=>@my_hash[b]['sort_date']
end
That should be:
sorted_keys = @my_hash.keys.sort do |a,b|
next result unless result=(@my_hash[a]['name']<=>@my_hash[b]['name']) == 0 @my_hash[a]['sort_date']<=>@my_hash[b]['sort_date']
end