Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Digit sum in Ruby 1.9.2
def digit_sum(n) {|c| c.to_i }.reduce(:+)

Shorter and more understandable with:

what about this one:
n.to_s.chars.inject { |sum,n| sum = sum.to_i + n.to_i}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment