RUBY: Check for duplicates in string #algorithm