Implementing ruby part (problem3)