I have the following function:
def valid_credit_card?(number)
digits = number.scan(/./).map(&:to_i)
check = digits.pop
sum = digits.reverse.each_slice(2).map do |x, y|
[(x * 2).divmod(10), y]
end.flatten.inject(:+)
(10 - sum % 10) == check
end
But for some reason I keep getting the following error message:
nil can't be coerced into Fixnum
And for some reason I can't figure out why the error is being thrown. Any ideas why this might be happening?