File: reduce.rb

Project: Invitation to Ruby

#!/usr/bin/env ruby

module Enumerable
  # Reduce has been added to the Ruby 1.7 library
  def reduce(init)
    result = init
    each { |item| result = yield(item, result) }
    result
  end
end

Used by: iterator reuse


[ Index ][ Table of Contents ]
Generated by [ source2html ]