def _checksum sum = 0 10.step( 2, -1 ) { |n| m = 10 - n sum += n * @isbn[m..m].to_i } checksum = ( 11 - ( sum % 11 ) ) % 11 checksum = 'X' if checksum == 10 return checksum.to_s end
Example 4: Ruby version of the _checksum routine shown in Example 3.