refactor ruby word coutn