文字列を受け取り、ユニコード文字をintに変換する次のメソッドがあります。Rubyでの総ユニコード文字
def uni_total(string)
string.ord
end
これは文字の合計です。私が文字列内のすべての文字を合計したければ、私は次のメソッドを試しました。
def uni_total(string)
string.ord each |item|
return item++
end
end
私はそれを実行keyword_endこれを回避するための最良の方法は何 リターンアイテム++ を期待して、私に次のエラーメッセージ」予期しないtIDENTIFIERを与えますか?どんな助けもありがとう。 よろしく
[この質問](https://stackoverflow.com/questions/3660563/why-doesnt-ruby-support-i--increment-decrement-operators)をチェックしてください。 ) '++'について、Rubyのdocs - ['String#codepoints'](http://ruby-doc.org/core/String.html#method-i-コードポイント)iまた、整数配列の合計を取得する方法については、[この質問](https://stackoverflow.com/questions/1538789/how-to-sum-array-of-numbers-in-ruby)を参照してください。そして、短い 'uni_total'実装、' string.codepoints.reduce(:+) 'で終わります。 – cremno
あなたの質問は不明です。 「文字の組み合わせを集める」とはどういう意味ですか? [Total Functions](https://wikipedia.org/wiki/Partial_function#Total_function)を参照していますか? –
答えは以下のとおりです。返信いただきありがとうございます。 – AltBrian