Skip to content

Instantly share code, notes, and snippets.

@tmaeda
Created September 20, 2012 07:59
Show Gist options
  • Save tmaeda/3754537 to your computer and use it in GitHub Desktop.
Save tmaeda/3754537 to your computer and use it in GitHub Desktop.
Procを再帰で呼べるかのテスト
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