Skip to content

Instantly share code, notes, and snippets.

@Sihui
Last active August 4, 2017 07:29
Show Gist options
  • Select an option

  • Save Sihui/8408471ca04a66435d8fa9d3861f2239 to your computer and use it in GitHub Desktop.

Select an option

Save Sihui/8408471ca04a66435d8fa9d3861f2239 to your computer and use it in GitHub Desktop.
Design Pattern: Iterator and Movie Collections
def get_all_movies
movies = []
while netflix_movie_iterator.has_next?
movies << netflix_movie_iterator.next
end
while amazon_movie_iterator.has_next?
movies << amazon_movie_iterator.next
end
while hulu_movie_iterator.has_next?
movies << hulu_movie_iterator.next
end
while youtube_movie_iterator.has_next?
movies << youtube_movie_iterator.next
end
while hbo_movie_iterator.has_next?
movies << hbo_movie_iterator.next
end
movies
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment