Recursive ruby impl