Skip to content

Instantly share code, notes, and snippets.

@taiki45
Created November 9, 2012 13:40
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 taiki45/4045707 to your computer and use it in GitHub Desktop.
Save taiki45/4045707 to your computer and use it in GitHub Desktop.
fun! ruby!
fact = lambda {
|pr, x| x * pr.((x - 1), pr)
}.curry.(lambda {|x, pr| x <= 0 ? 1 : x * pr.((x - 1), pr) })
a = Class.new.instance_exec(fact) do |fact|
define_method(:fact, fact)
self
end.new
p a.fact 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment