Ruby: Module, Mixins and Blocks confusing?
Following is the code I tried to run from the Ruby Programming Book http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_modules.html Why doesn't the product method give the right output? I ran it with irb test.rb . And I am running Ruby 1.9.3p194 . module Inject def inject(n) each do |value| n = yield(n, value) end n end def sum(initial = 0) inject(initial) { |n, value| n + value } end def product(initial = 1) inject(initial) { |n, value| n * value } end end class Array include Inject end [1, 2, 3, 4, 5].sum ## 15 [1, 2, 3, 4, 5].product ## [[1], [2], [3], [4], [5]] By the way: in Ruby 2.0,