Resolution of exercise 2 in Ruby Language