Skip to content

Instantly share code, notes, and snippets.

@Sihui
Last active August 4, 2017 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sihui/9ab08ea24b39c5a1c12575e9dbeaf8d3 to your computer and use it in GitHub Desktop.
Save Sihui/9ab08ea24b39c5a1c12575e9dbeaf8d3 to your computer and use it in GitHub Desktop.
Design Pattern: Iterator and Movie Collections
def get_all_movies
movies = []
movie_iterators = [
netflix_movie_iterator,
amazon_movie_iterator,
hulu_movie_iterator,
youtube_movie_iterator,
hbo_movie_iterator
]
movie_iterators.each do |movie_iterator|
while movie_iterator.has_next?
movies << movie_iterator.next
end
end
movies
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment