문자열을 가져와 유니 코드 문자를 int로 변환하는 다음과 같은 메서드가 있습니다.Ruby의 총 유니 코드 문자
def uni_total(string)
string.ord
end
문자 합계입니다. 문자열의 모든 문자를 합산하려면 다음 방법을 시도했습니다.
def uni_total(string)
string.ord each |item|
return item++
end
end
나는 그것이 나에게 '예상치 못한 tIDENTIFIER 다음과 같은 오류 메시지, keyword_end 반환 항목 ++ 이 주위에 얻을 수있는 가장 좋은 방법은 무엇입니까 기대를주고 실행하면? 어떤 도움을 주시면 감사하겠습니다. 감사
[이 질문] (https://stackoverflow.com/questions/3660563/why-doesnt-ruby-support-i--i-increment-decrement-operators)을 확인하십시오.)에 대한'++', Ruby 문서 - ['String # codepoints'] (http://ruby-doc.org/core/String.html#method-i-code point) i n 그리고 또한 [이 질문] (https://stackoverflow.com/questions/1538789/how-to-sum-array-of-numbers-in-ruby) 정수 배열의 합계를 얻는 방법을 배우십시오. 그런 다음 짧은'uni_total' 구현으로 끝납니다 :'string.codepoints.reduce (: +)'. – cremno
질문이 확실하지 않습니다. "문자 조합을 합하는 것"은 무엇을 의미합니까? [총 기능] (https://wikipedia.org/wiki/Partial_function#Total_function)을 말하고 있습니까? –
답변은 아래와 같습니다. 답장을 보내 주셔서 감사합니다. – AltBrian