Top Level Namespace

Defined Under Namespace

Modules: Enumerable, Threadify Classes: Object, Thread

Instance Method Summary collapse

Instance Method Details

#Threadify(*args, &block) ⇒ Object


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/threadify.rb', line 25

def Threadify(*args, &block)
  # setup
  #
    opts = args.last.is_a?(Hash) ? args.pop : {}
    opts.keys.each{|key| opts[key.to_s.to_sym] = opts.delete(key)}
    opts[:threads] ||= (Numeric === args.first ? args.shift : Threadify.threads)
    opts[:strategy] ||= (args.empty? ? Threadify.strategy : args)

    threads = Integer(opts[:threads])

    array_of_blocks = Array.new(threads){ block }
    array_of_blocks.threadify(opts){|b| b.call()}
end