Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created April 14, 2009 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itspriddle/95462 to your computer and use it in GitHub Desktop.
Save itspriddle/95462 to your computer and use it in GitHub Desktop.
def valid_card?(num)
odd = true
num.to_s.gsub(/\D/,'').reverse.split('').map(&:to_i).collect { |d|
d *= 2 if odd = !odd
d > 9 ? d - 9 : d
}.sum % 10 == 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment