Module: Twitter::Utils
- Included in:
- Base, Client, Cursor, Error, GeoResults, PremiumSearchResults, REST::AccountActivity, REST::DirectMessages, REST::DirectMessages::WelcomeMessages, REST::Favorites, REST::FriendsAndFollowers, REST::Lists, REST::Request, REST::SavedSearches, REST::Tweets, REST::Users, REST::Utils, SearchResults, Streaming::Client, TrendResults
- Defined in:
- lib/twitter/utils.rb
Class Method Summary collapse
-
.flat_pmap(enumerable, &block) ⇒ Array, Enumerator
Returns a new array with the concatenated results of running block once for every element in enumerable.
-
.pmap(enumerable, &block) ⇒ Array, Enumerator
Returns a new array with the results of running block once for every element in enumerable.
Class Method Details
.flat_pmap(enumerable, &block) ⇒ Array, Enumerator
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.
10 11 12 13 14 |
# File 'lib/twitter/utils.rb', line 10 def flat_pmap(enumerable, &block) return to_enum(:flat_pmap, enumerable) unless block pmap(enumerable, &block).flatten(1) end |
.pmap(enumerable, &block) ⇒ Array, Enumerator
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.
21 22 23 24 25 26 27 28 29 |
# File 'lib/twitter/utils.rb', line 21 def pmap(enumerable, &block) return to_enum(:pmap, enumerable) unless block if enumerable.count == 1 enumerable.collect(&block) else enumerable.collect { |object| Thread.new { yield(object) } }.collect(&:value) end end |