Module: Twitter::Enumerable

Includes:
Enumerable
Included in:
Cursor, GeoResults, PremiumSearchResults, SearchResults, TrendResults
Defined in:
lib/twitter/enumerable.rb

Overview

Provides iteration support for collections

Instance Method Summary collapse

Instance Method Details

#each(start = 0) {|Object| ... } ⇒ Enumerator

Iterates over the collection

Examples:

cursor.each { |item| puts item }

Parameters:

  • start (Integer) (defaults to: 0)

    The starting index

Yields:

  • (Object)

    Each item in the collection

Returns:

  • (Enumerator)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/twitter/enumerable.rb', line 14

def each(start = 0, &block)
  return to_enum(:each, start) unless block

  Array(@collection[start..]).each(&block) # steep:ignore FallbackAny
  unless finished?
    start = [@collection.size, start].max # steep:ignore FallbackAny
    fetch_next_page
    each(start, &block)
  end
  self
end