Module Enumerable
In: lib/more/facets/enumargs.rb
lib/more/facets/thread.rb

This is a simple reimplementation of the core Enumerable module to allow the methods to take and pass-on arbitrary arguments to the underlying each call. This library uses Enumerator and scans Enumerable so it can alwasy stay in sync.

NOTE Any Enumerable method with a negative arity cannot do pass arguments due to ambiguity in the argument count. So the methods inject and zip do NOT work this way, but simply work as they do in Enumerable. The method find (and detect) though has been made to work by removing its rarely used optional parameter and providing instead an optional keyword parameter (:ifnone => …). Please keep these difference in mind.

  require 'enumargs'

  class T
    include Enumerable::Arguments
    def initialize(arr)
      @arr = arr
    end
    def each(n)
      arr.each{ |e| yield(e+n) }
    end
  end

  t = T.new([1,2,3])
  t.collect(4)
  #=> [5,6,7]

Methods

Classes and Modules

Module Enumerable::Arguments

Public Instance methods

Like Enumerable#map but each iteration is processed via a separate thread.

CREDIT Sean O‘Halpin

[Source]

    # File lib/more/facets/thread.rb, line 37
37:   def threaded_map #:yield:
38:     map{ |e| Thread.new(e){ |t| yield(t) } }.map{ |t| t.value }
39:   end

Like Enumerable#map_send but each iteration is processed via a separate thread.

CREDIT Sean O‘Halpin

[Source]

    # File lib/more/facets/thread.rb, line 46
46:   def threaded_map_send(meth, *args, &block)
47:     map{ |e| Thread.new(e){ |t| t.send(meth, *args, &block) } }.map{ |t| t.value }
48:   end

[Validate]