From: Christopher Dicely Date: 2009-04-01T08:05:13+09:00 Subject: Re: Why does mathn kill this method? On Tue, Mar 31, 2009 at 3:46 PM, Siep Korteling wrote: > Really stumped here. > > def sum_digits(n) >    sum = 0 >    while n>0 >       sum += n % 10 >       n /= 10 >       end >    sum >  end > > STDOUT.sync=true > > puts sum_digits(12) #=> 3 > > require 'mathn' > puts sum_digits(12) # hangs > > > What am I doing wrong? This should illustrate the problem: irb(main):001:0> require 'mathn' => true irb(main):002:0> n = 10 => 10 irb(main):003:0> n /= 10 => 1 irb(main):004:0> n /= 10 => 1/10 irb(main):005:0> n /= 10 => 1/100 The solution: def sum_digits(n) sum = 0 while n>0 sum += n % 10 n = n.div 10 end sum end