doing some tree traversal with recursive functions and ruby