Module: Twitter::Utils

Included in:
Base, Client, Cursor, GeoResults, REST::DirectMessages, REST::Favorites, REST::FriendsAndFollowers, REST::Lists, REST::SavedSearches, REST::Tweets, REST::Users, REST::Utils, SearchResults, TrendResults
Defined in:
lib/twitter/utils.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary (collapse)

Class Method Details

+ (Array, Enumerator) flat_pmap(enumerable)

Returns a new array with the concatenated results of running block once for every element in enumerable. If no block is given, an enumerator is returned instead.



27
28
29
30
# File 'lib/twitter/utils.rb', line 27

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

+ (Array, Enumerator) pmap(enumerable)

Returns a new array with the results of running block once for every element in enumerable. If no block is given, an enumerator is returned instead.



38
39
40
41
42
43
44
45
# File 'lib/twitter/utils.rb', line 38

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