Rails interview problem solution