Created
September 26, 2009 01:29
-
-
Save sigmonsays/193969 to your computer and use it in GitHub Desktop.
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
sort_func = Proc.new { |a,b| | |
b[1] <=> a[1] | |
} | |
h = { | |
'foo' => 5, | |
'bar' => 50, | |
'baz' => 500, | |
} | |
# i want something like this.. where sort_func can be passed in like an argument: | |
# sorted = h.sort sort_func | |
# sorted.each { |k,v| | |
# puts "#{k} #{v}" | |
# } | |
# This can also be written as | |
h.sort { |a,b| b[1] <=> a[1] }.each { |k,v| | |
puts "#{k} #{v}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment