Try to build a class with it and you will understand.
I see.....
Anyway, this is elegant to me:
sum ||= (1..100000).to_a.inject(:+)
Maybe you have a different aesthetical sense than the rest of us. That's perfectly fine, we don't have to like the same things.
But since you questioned, now I'm curious and I would like to ask you: what language in your opinion has the most elegant syntax? Also if you have 2 extra minutes free, would you mind to code that same one-liner above in that language so we could compare the two?
(reduce + (range 1 100001))
but you can make yours a little nicer by relying on a Range being enumerable, hence:
(1..100000).inject(:+)
+/>:i.100001
You could takeout the >: but then the range is 0 indexed and not 1-based: +/i.100001The Lisp family, Scheme in particular.
(define sum (reduce + 0 (iota 100000 1)))