开发者

Recursive stack size

How i can know 开发者_运维知识库the current method stack frame while a recursive call in ruby?


I have no idea why you would need that, but caller.size should do the job:

def recurse(n)
  puts caller.size
  recurse(n-1) unless n <= 0
end

recurse(5)  # => Outputs 1 to 6

This works in Ruby 1.9, but there is apparently a bug in Ruby 1.8. Just filed it on redmine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜