Skip to content

Instantly share code, notes, and snippets.

@brunto
Created August 17, 2012 12:19
Show Gist options
  • Save brunto/3378398 to your computer and use it in GitHub Desktop.
Save brunto/3378398 to your computer and use it in GitHub Desktop.
Ruby sort_by
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