Skip to content

Instantly share code, notes, and snippets.

@nonowarn
Created July 15, 2010 13:23
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 nonowarn/476929 to your computer and use it in GitHub Desktop.
Save nonowarn/476929 to your computer and use it in GitHub Desktop.
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