### Home Classes Methods

### In Files

- lib/twitter/utils.rb

### Namespace

- MODULE Twitter::Utils::ClassMethods

### Methods

- ::flat_pmap
- ::included
- ::pmap
- ::pmap_with_index

### Class/Module Index

Quicksearch

- Twitter
- Twitter::Arguments
- Twitter::Base
- Twitter::BasicUser
- Twitter::Client
- Twitter::Configuration
- Twitter::Creatable
- Twitter::Cursor
- Twitter::DirectMessage
- Twitter::Entities
- Twitter::Entity
- Twitter::Entity::Hashtag
- Twitter::Entity::Symbol
- Twitter::Entity::URI
- Twitter::Entity::URL
- Twitter::Entity::UserMention
- Twitter::Enumerable
- Twitter::Error
- Twitter::Error::AlreadyFavorited
- Twitter::Error::AlreadyRetweeted
- Twitter::Error::BadGateway
- Twitter::Error::BadRequest
- Twitter::Error::ClientError
- Twitter::Error::Code
- Twitter::Error::ConfigurationError
- Twitter::Error::DuplicateStatus
- Twitter::Error::Forbidden
- Twitter::Error::GatewayTimeout
- Twitter::Error::InternalServerError
- Twitter::Error::NotAcceptable
- Twitter::Error::NotFound
- Twitter::Error::RequestTimeout
- Twitter::Error::ServerError
- Twitter::Error::ServiceUnavailable
- Twitter::Error::TooManyRequests
- Twitter::Error::UnacceptableIO
- Twitter::Error::Unauthorized
- Twitter::Error::UnprocessableEntity
- Twitter::Factory
- Twitter::Geo
- Twitter::Geo::Point
- Twitter::Geo::Polygon
- Twitter::GeoFactory
- Twitter::GeoResults
- Twitter::Identity
- Twitter::Language
- Twitter::List
- Twitter::Media
- Twitter::Media::Photo
- Twitter::MediaFactory
- Twitter::Metadata
- Twitter::OEmbed
- Twitter::Place
- Twitter::Profile
- Twitter::ProfileBanner
- Twitter::REST
- Twitter::REST::API
- Twitter::REST::Client
- Twitter::REST::DirectMessages
- Twitter::REST::Favorites
- Twitter::REST::FriendsAndFollowers
- Twitter::REST::Help
- Twitter::REST::Lists
- Twitter::REST::OAuth
- Twitter::REST::PlacesAndGeo
- Twitter::REST::Request
- Twitter::REST::Request::MultipartWithFile
- Twitter::REST::Response
- Twitter::REST::Response::ParseErrorJson
- Twitter::REST::Response::ParseJson
- Twitter::REST::Response::RaiseError
- Twitter::REST::SavedSearches
- Twitter::REST::Search
- Twitter::REST::SpamReporting
- Twitter::REST::SuggestedUsers
- Twitter::REST::Timelines
- Twitter::REST::Trends
- Twitter::REST::Tweets
- Twitter::REST::Undocumented
- Twitter::REST::Users
- Twitter::REST::Utils
- Twitter::RateLimit
- Twitter::Relationship
- Twitter::Request
- Twitter::SavedSearch
- Twitter::SearchResults
- Twitter::Settings
- Twitter::Size
- Twitter::SourceUser
- Twitter::Streaming
- Twitter::Streaming::Client
- Twitter::Streaming::Connection
- Twitter::Streaming::DeletedTweet
- Twitter::Streaming::Event
- Twitter::Streaming::FriendList
- Twitter::Streaming::MessageParser
- Twitter::Streaming::Response
- Twitter::Streaming::StallWarning
- Twitter::Suggestion
- Twitter::TargetUser
- Twitter::Token
- Twitter::Trend
- Twitter::TrendResults
- Twitter::Tweet
- Twitter::User
- Twitter::Utils
- Twitter::Utils::ClassMethods
- Twitter::Version

No matching classes.

# Twitter::Utils

### Public Class Methods

flat_pmap(enumerable) click to toggle source

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.

@param enumerable [Enumerable] @return [Array, Enumerator]

    # File lib/twitter/utils.rb, line 27
    def flat_pmap(enumerable)
      if block_given?
        pmap(enumerable, &Proc.new).flatten(1)
      else
        to_enum(:flat_pmap, enumerable)
      end
    end

included(base) click to toggle source

    # File lib/twitter/utils.rb, line 4
    def included(base)
      base.extend(ClassMethods)
    end

pmap(enumerable) click to toggle source

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.

@param enumerable [Enumerable] @return [Array, Enumerator]

    # File lib/twitter/utils.rb, line 41
    def pmap(enumerable)
      return to_enum(:pmap, enumerable) unless block_given?
      pmap_with_index(enumerable).sort_by { |_, index| index }.collect { |object, _| yield(object) }
    end

pmap_with_index(enumerable) click to toggle source

Calls block with two arguments, the item and its index, for each item in enumerable. Given arguments are passed through to pmap. If no block is given, an enumerator is returned instead.

@param enumerable [Enumerable] @return [Array, Enumerator]

    # File lib/twitter/utils.rb, line 52
    def pmap_with_index(enumerable)
      return to_enum(:pmap_with_index, enumerable) unless block_given?
      # Don't bother spawning a new thread if there's only one item
      if enumerable.count == 1
        enumerable.collect { |object| yield(object, 0) }
      else
        enumerable.each_with_index.collect { |object, index| Thread.new { yield(object, index) } }.collect(&:value)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.