finished solution for Ruby