Created
July 15, 2010 13:23
-
-
Save nonowarn/476929 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Proc | |
def on(g) | |
f = self | |
-> a, b { f[g[a], g[b]] } | |
end | |
end | |
class Symbol | |
def to_func | |
-> this, *args { this.__send__ self, *args } | |
end | |
end | |
module ProcUtils | |
def comparing(&g) | |
:<=>.to_func.on(g) | |
end | |
end | |
if $0 == __FILE__ | |
include ProcUtils | |
p [1,2,3,4].sort(&comparing(&:-@)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment