I have the following method that takes a string and converts the unicode character to an int.
def uni_total(string) string.ord end This will total a character. If I wanted to total all of the characters in a string I have tried the following method.
def uni_total(string) string.ord each |item| return item++ end end When I run it give me the following error message 'unexpected tIDENTIFIER, expecting keyword_end return item++ What is the best way to get around this? Any help would be appreciated. Regards
++, the Ruby docs -String#codepointsin particular and also this question to learn how to get the sum of an integer array. Then you end up with a shortuni_totalimplementation:string.codepoints.reduce(:+).