Skip to content

Instantly share code, notes, and snippets.

@plonk
Created July 21, 2013 16:07
Show Gist options
  • Select an option

  • Save plonk/6048962 to your computer and use it in GitHub Desktop.

Select an option

Save plonk/6048962 to your computer and use it in GitHub Desktop.
無名関数を再帰させる構造
def make_recur(&def_block)
delegate = proc { |*args|
user_proc = def_block.call(delegate)
user_proc.call(*args)
}
end
p make_recur { |myproc|
proc { |n|
(n == 1) ? 1 : n * myproc.call(n-1)
}
}.call(5)
# OUTPUT: 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment