Sha256: d0ea3086b6da70f34a93de6c8b201e30f195ecead7505814e1fdd1fab957bc53
Contents?: true
Size: 432 Bytes
Versions: 21
Compression:
Stored size: 432 Bytes
Contents
# == CreditCardValidations Luhn # simple class to validate Luhn numbers. # # Luhn.valid? 4111111111111111 # module CreditCardValidations class Luhn def self.valid?(number) s1 = s2 = 0 number.to_s.reverse.chars.each_slice(2) do |odd, even| s1 += odd.to_i double = even.to_i * 2 double -= 9 if double >= 10 s2 += double end (s1 + s2) % 10 == 0 end end end
Version data entries
21 entries across 21 versions & 2 rubygems