This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class GroupContact | |
| attr_reader :group | |
| def initialize(people_in_group) | |
| @group = people_in_group | |
| end | |
| def message(text) | |
| group.each do |person| | |
| person.message(text) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PersonContact | |
| attr_reader :title, :number | |
| def initialize(title, number) | |
| @title = title | |
| @number = number | |
| end | |
| def message(text) | |
| puts "Messaging #{title}(#{number}): " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HashIterator | |
| attr_reader :collection, :keys | |
| attr_accessor :current_index | |
| def initialize(collection) | |
| @collection = collection | |
| @keys = collection.keys | |
| @current_index = 0 | |
| end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ArrayIterator | |
| attr_reader :collection | |
| attr_accessor :current_index | |
| def initialize(collection) | |
| @collection = collection | |
| @current_index = 0 | |
| end | |
| def has_next? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_all_movies | |
| movies = [] | |
| movie_iterators = [ | |
| netflix_movie_iterator, | |
| amazon_movie_iterator, | |
| hulu_movie_iterator, | |
| youtube_movie_iterator, | |
| hbo_movie_iterator | |
| ] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MovieCollection | |
| attr_reader :netflix_movies, :amazon_movies, | |
| :hulu_movies, :youtube_movies, :hbo_movies | |
| attr_accessor :all_movies | |
| def initialize(netflix_movies, amazon_movies, | |
| hulu_movies, youtube_movies, hbo_movies) | |
| @netflix_movies = netflix_movies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MovieCollection | |
| attr_reader :netflix_movies, :amazon_movies | |
| def initialize(netflix_movies, amazon_movies) | |
| @netflix_movies = netflix_movies | |
| @amazon_movies = amazon_movies | |
| @all_movies = get_all_movies | |
| end | |
| private |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| amazon_movies = { | |
| 0 => { | |
| title: 'Mission: Impossible - Rogue Nation', | |
| year: '2015', | |
| director: 'Christopher McQuarrie', | |
| genre: 'Thriller/Actio', | |
| length: '2h 11m' | |
| }, | |
| 1 => { | |
| title: 'The Hunger Games: Mockingja', |