Created
August 17, 2012 12:19
-
-
Save brunto/3378398 to your computer and use it in GitHub Desktop.
Ruby sort_by
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pdf_info = { | |
"John"=>{"format_b"=>{"file_z"=>{:quantity=>1, :free=>false}, "file_f"=>{:quantity=>1, :free=>true}}}, | |
"Brunto"=>{"format_a"=>{"file_w"=>{:quantity=>1, :free=>false}, "file_g"=>{:quantity=>1, :free=>true}}} | |
} | |
new_pdf_info = {} | |
pdf_info = pdf_info.sort_by {|k| k} | |
pdf_info.each do |customer, format_orders| | |
new_pdf_info[customer] = {} | |
format_orders.each do |format, orders| | |
new_pdf_info[customer][format] = {} | |
new_pdf_info[customer][format] = Hash[orders.sort_by {|k| k}] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment