Module: Teamsupport::Utils

Included in:
Base, REST::Customers, REST::Products, REST::Tickets, REST::Utils
Defined in:
lib/teamsupport/utils.rb

Class Method Summary collapse

Class Method Details

.flat_pmap(enumerable) ⇒ Array, Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns new array with concatenated results of running block for every element

Parameters:

  • enumerable (Enumerable)

Returns:

  • (Array, Enumerator)


12
13
14
15
# File 'lib/teamsupport/utils.rb', line 12

def flat_pmap(enumerable)
  return to_enum(:flat_pmap, enumerable) unless block_given?
  pmap(enumerable, &Proc.new).flatten(1)
end

.pmap(enumerable) ⇒ Array, Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns new array with the results of running block once for every element

Parameters:

  • enumerable (Enumerable)

Returns:

  • (Array, Enumerator)


24
25
26
27
28
29
30
31
# File 'lib/teamsupport/utils.rb', line 24

def pmap(enumerable)
  return to_enum(:pmap, enumerable) unless block_given?
  if enumerable.count == 1
    enumerable.collect { |object| yield(object) }
  else
    enumerable.collect { |object| Thread.new { yield(object) } }.collect(&:value)
  end
end