Skip to content

Instantly share code, notes, and snippets.

@EnriqueVidal
Created February 28, 2012 21:34
Show Gist options
  • Save EnriqueVidal/1935303 to your computer and use it in GitHub Desktop.
Save EnriqueVidal/1935303 to your computer and use it in GitHub Desktop.
Luhn implementation
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