Created
February 28, 2012 21:34
-
-
Save EnriqueVidal/1935303 to your computer and use it in GitHub Desktop.
Luhn implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def luhn_checksum | |
odd = true | |
checksum = card_number.reverse.split(//).map(&:to_i).map do |digit| | |
digit *= 2 if odd = !odd | |
digit > 9 ? digit - 9 : digit | |
end.sum | |
checksum % 10 == 0 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment