From: Mr Jaba Date: 2011-11-30T23:20:50+09:00 Subject: Re: Stupid question --000e0ce02ace3e2fe204b2f4714a Content-Type: text/plain; charset=ISO-8859-1 I'm sure someone will come up with a better solution, but a quick and dirty way would be to convert it to a string then split it: 2011.to_s.split(//).inject(0){|sum, a| sum + a.to_i} Like I say, not the cleanest, but it works. Hope that helps. On 30 November 2011 14:10, 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/. > > --000e0ce02ace3e2fe204b2f4714a--