Skip to content

Instantly share code, notes, and snippets.

@nicklewis
Created April 27, 2011 06:55
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 nicklewis/943824 to your computer and use it in GitHub Desktop.
Save nicklewis/943824 to your computer and use it in GitHub Desktop.
Array#to_proc
class Proc
def *(g)
raise ArgumentError, "arity count mismatch" unless arity == g.arity
proc { |*a| self[*g[*a] ] }
end
end
class Array
def to_proc
map(&:to_proc).reverse.inject(&:*)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment