Skip to content

Instantly share code, notes, and snippets.

@Sihui
Last active August 4, 2017 07:33
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/d84e7cab643c2ace797148071d2b3dcb to your computer and use it in GitHub Desktop.
Save Sihui/d84e7cab643c2ace797148071d2b3dcb to your computer and use it in GitHub Desktop.
Design Pattern: Iterator and Movie Collections
class MovieCollection
attr_reader :movie_iterators
attr_accessor :all_movies
def initialize(movie_iterators)
@movie_iterators = movie_iterators
@all_movies = get_all_movies
end
private
def get_all_movies
movies = []
movie_iterators.each do |movie_iterator|
while movie_iterator.has_next?
movies << movie_iterator.next
end
end
movies
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment