From: "Jan E." Date: 2012-09-28T18:25:22+09:00 Subject: Re: calcaulation with unknown numbers of numbers and options fail Roelof Wobben wrote in post #1077868: > Can you explain the how the operator and the reduce work. First of all, I most correct the code: It should be operator = options.empty? || options[:add] ? :+ : :- to make addition the default. What I've written down is simply the short form of "inject": http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-inject Instead of passing a block, you can also pass a method name or operator (as a symbol). The elements will then be aggregated using this method/operator. So [1, 2, 3].inject :+ is the same as [1, 2, 3].inject {|sum, element| sum + element} But it's obviously shorter. When you use the short form, it's common to use the method name "reduce" instead of "inject" (but both are the same method). And the "operator" variable is used to specify the operator for "reduce" according to the option hash. -- Posted via http://www.ruby-forum.com/.