Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

String#sum

str.sum(n=16) → integer

Returns a basic n-bit checksum of the characters in str, where n is the optional Integer parameter, defaulting to 16. The result is simply the sum of the binary value of each byte in str modulo 2**n - 1. This is not a particularly good checksum.

See also #succ! #swapcase #succ #swapcase! also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1