Conversation
…ummary method to Planet.rb
…solar_system with adjusted varibale titles
…method in main.rb. Formatting
Solar SystemWhat We're Looking For
Good work on this project, Macaria! Your code was logical, thoughtful, and well-organized. In particular, you did a FANTASTIC job of creating helper methods and paying close attention to detail-- I can tell from all of the edge cases that you coded for. I've added a few comments about tiny suggestions for improvement. Overall, well done! Great work! |
|
|
||
| # Format attributes of instances od planets into a neat string. | ||
| def summary | ||
| puts "The planet #{@name} is #{@color} in color and is #{"%1e" % @mass_kg} kgs. |
There was a problem hiding this comment.
Great job with always making sure that the numbers are formatted!
|
|
||
| # Format attributes of instances od planets into a neat string. | ||
| def summary | ||
| puts "The planet #{@name} is #{@color} in color and is #{"%1e" % @mass_kg} kgs. |
There was a problem hiding this comment.
Our requirements asked for the summary method to return a string, not puts it, and to shift the responsibility of putsing things to the main method. :(
| if planet.name.downcase == planet_to_find.downcase | ||
| return planet | ||
| end | ||
| end |
There was a problem hiding this comment.
If you had more time to refactor, consider refactoring this each loop with a find
| return planet | ||
| end | ||
| end | ||
| return nil_planet = Planet.new(name: "", color: "", mass_kg: 1, distance_from_sun_km: 1, fun_fact: "") |
There was a problem hiding this comment.
Interesting/clever solution to return an empty Planet!
Also, in this line, you are doing a few things: Creating a new instance of Planet, assigning it to the local variable nil_planet, and then returning that value. It would make the same amount of sense without the variable assignment, so, return Planet.new(...)
| exploder = Planet.new(name: "Exploder", color: "fire", mass_kg: 1.847e26, distance_from_sun_km: 1.0826e5, fun_fact: "Exploder is too close to the Sun. It is going to explode.") | ||
| untenable.add_planet(poddo) | ||
| untenable.add_planet(normie) | ||
| untenable.add_planet(exploder) |
| while untenable.find_planet_by_name(user_planet).name != "" | ||
| puts "A planet with that name already exists. Try and be ORIGINAL." | ||
| user_planet = get_string.downcase | ||
| end |
There was a problem hiding this comment.
Fantastic work checking for this use case! This is a great edge case to account for
| end | ||
|
|
||
| # Helper method to obtain user input of planet names and use find_planet_by_name(solar_system.rb) to validate it | ||
| def get_planet(solar_system) |
There was a problem hiding this comment.
NIIIIIICE! :) All of these helper methods are soooo good and so necessary!
| planet = gets.chomp.downcase | ||
| planet_select = solar_system.find_planet_by_name(planet) | ||
|
|
||
| while planet_select.name.downcase != planet |
There was a problem hiding this comment.
If you didn't always return a new instance of Planet from the find_planet_by_name method in cases where there was no matching planet, this conditional would be different and you wouldn't have to check planet_select.name.downcase. For example, if that method returned nil when it didn't find any planet, then this while could look like while planet_select == nil (or even shorter: while !planet_select)
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initializemethod run? What does it do?Hashinstead of an instance of a class?SolarSystemclass used aHashinstead of anArrayto store the list of planets?requirestatements? Which files neededrequires, and which did not? What is the pattern?