Too Cool for Internet Explorer

Monday, December 15, 2008

Test on color code

This is a test on posting colorized code here on Blogger:

def creditcard?(type = nil)
number = self.to_s.gsub(/[^\d]/, "")
return false unless number.length >= 13

if type
return false unless creditcard_type == type
end

sum = 0
for i in 0..number.length
weight = number[-1*(i+2), 1].to_i * (2 - (i%2))
sum += (weight < 10) ? weight : weight - 9
end

return true if number[-1,1].to_i == (10 - sum%10)%10
return false
end

After that I have edited the post to check the consequences...

And then edited another time to fix it... Very fast.

And here is the source: A Brent Sowers' article.

No comments: