From: Sylvester Keil Date: 2011-12-01T01:47:35+09:00 Subject: Re: Stupid question How about this one? n = 2011 n.size.pred.downto(0).reduce(0) { |sum, a| sum += (n.abs / 10 ** a) % 10 } On Nov 30, 2011, at 3:10 PM, James Gallagher wrote: > Hi everyone. > > I have a really stupid question here, but i'm a newbie so hear me out. > > I want to add together all the digets in a number. > (for example, 2011 would be 4). > but i want to do it with a program. > > I don't know how to split the individual digits up. > > Thank you so much. > > James. :-) > > -- > Posted via http://www.ruby-forum.com/. >