Recursive functions for Ruby that won't eat all your stacks