ruby 一个简单的递归示例。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 一个简单的递归示例。相关的知识,希望对你有一定的参考价值。

def peel(vegetable_with_layers)
  if vegetable_with_layers[0] == 'core'
    # base case: have I reached the core?
    vegetable_with_layers[0]
  else
    # not the core... remove one layer
    peel(vegetable_with_layers[0])
  end
end

onion = [[['core']]]
peel(onion)

以上是关于ruby 一个简单的递归示例。的主要内容,如果未能解决你的问题,请参考以下文章