Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think that Ruby code will do what the original poster at the language shootout thought it would, as it's not equivalent to the Java code above it. If it were correct though, you could improve it by being more Ruby-like and doing it like this:

puts STDIN.inject {|sum, next_number| sum.to_i + next_number.to_i}

. . . or something.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: