Logan Capaldo wrote:
> num_s =  num.to_s
> (0...(num_s.length)).inject(0) { |s, i| s += (num_s[i]  - ?0) }

require 'enumerator'
num.to_s.enum_for(:each_byte).inject(0) { |sum, c| sum + c - ?0 }

Or, in Ruby 1.9 (I think):
num.to_s.each_byte.inject(0) { |sum, c| sum + c - ?0 }

Cheers,
Dave