Skip to content

Instantly share code, notes, and snippets.

@sgharms
Created August 15, 2011 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgharms/1148023 to your computer and use it in GitHub Desktop.
Save sgharms/1148023 to your computer and use it in GitHub Desktop.
unclemantis
#!/usr/bin/env ruby
#
foo = []
0.upto 5 do |i|
- foo[i] = {}
end
foo[0]['jackpot'] = 100
foo[1]['jackpot'] = 200
foo[2]['jackpot'] = 500
foo[3]['jackpot'] = 300
foo[4]['jackpot'] = 250
foo[5]['jackpot'] = 9
require 'pp'
# Non-destructive, foo is unchanged.
#pp foo.sort_by{|x| x['jackpot']}
#pp foo
# Fix it for good
pp foo.sort_by!{|x| x['jackpot']}
pp foo
-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment