Open
Conversation
added 22 commits
February 18, 2020 15:43
…ystem, add Planets to it, print the list
…instance instead of the summary
…nter a control loop
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Assignment Submission: Solar System
Congratulations! You're submitting your assignment. Please reflect on the assignment with these questions.
Reflection
initializemethod run? What does it do?initializemethod is called when an instance of a class is created (e.g.,Planet.new). It is used to construct a new object of the associated class. It can accept arguments and store them as instance variables within the class methods.Hashinstead of an instance of a class?SolarSystemwould be an array of hashes, and eachPlanetwould be a hash within that array. The planet details would be stored as key-value pairs in each hash (e.g.,earth = {name: "Earth", color: "blue-green}. The entire program would likely be coded in one file or with just one other file for defining the SolarSystem class. Each time I wanted to access a detail of a planet, I would need to refer to it by its key rather than call a class method (e.g.,planet[:name]instead ofplanet.name). Adding new planets would require methods that create a new hash and shovel it into the array of planets, rather than passing arguments throughPlanet.new.SolarSystemclass used aHashinstead of anArrayto store the list of planets?@planets = Hash.newto theinitializemethod of theSolarSystemclass, and I might store eachPlanetinstance as a key-value pair (e.g.,{earth: #<Planet:0x00007ff472138ff8>, mars: #<Planet:0x00007ff86f8ccdb8>}). I would also need to change the iteration variables (e.g., fromplanettokey, value) in the enumerable methods I used for the list_planets and find_planet_by_name methods. I would also need to change the code block of these methods so I could access the planet name through its key rather than within the class method (e.g.,planet[:name]instead ofplanet.name). This would probably break a lot of things and require some experimentation with the data structure to work properly!Planetclass is responsible for handling the creation of new planets, which includes storing planet details to instance variables and returning a summary. TheSolarSystemclass is responsible for handling the creation of new solar systems, which includes grouping and finding planets within each system.requirestatements? Which files neededrequires, and which did not? What is the pattern?requirestatements at the top of the main.rb in order of file creation (i.e.,require_relative: 'planet'is at the top since it was the first file created). I also added require statements to the planet_test.rb file, although I didn't have time to get my minitests working. The files solar_system.rb and planet.rb did not needrequirestatements.