Created
September 20, 2012 07:59
-
-
Save tmaeda/3754537 to your computer and use it in GitHub Desktop.
Procを再帰で呼べるかのテスト
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
def foo(ary) | |
rec = Proc.new do |ary| | |
if ary == [] | |
next 0 | |
else | |
rtn = ary[0] + rec.call(ary[1..-1]) | |
next rtn | |
end | |
end | |
rec.call(ary) | |
end | |
foo((1..10).to_a) => 55 | |
# 呼べた |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment