From: Ryan Leavengood Date: 2007-05-03T23:25:38+09:00 Subject: Re: [SUMMARY] Checking Credit Cards (#122) On 5/3/07, Rick DeNatale wrote: > > After seeing the neat use of each_slice instead of each_with_index > > def luhn(string) > string.scan(/./).reverse.enum_for(:each_slice, 2).inject(0) do |sum, (d1, d2)| > sum += d1.to_i + (d2||'0').tr('0123456789', '0246813579').to_i > end % 10 == 0 > end > > No need to define any extra Enumerator methods. Nice, I like it. When I first thought about using enum_for(:each_slice, 2) I was surprised that it even worked. Enumerator is a powerful library. It seems like I learn something new every time I do one of these quizzes, either from making my own solution or reading someone else's. Ryan