Skip to content

Instantly share code, notes, and snippets.

@Rojo
Last active August 29, 2015 14:01
Show Gist options
  • Save Rojo/6d6ad947505fc917a72a to your computer and use it in GitHub Desktop.
Save Rojo/6d6ad947505fc917a72a to your computer and use it in GitHub Desktop.
A simple recursion example.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment