Conversation
…or input their own planets
unused copy
Solar SystemWhat We're Looking For
Well done on this project, Kelsey! Your object-oriented code is great; it's logical and has good code style. You also did a great job of doing a lot of good code best practices, like making helper methods. I think that if you take a fresh look at your code in Besides those comments, your code otherwise looks great; you did a great job determining a user flow (with the generic planets, etc). Keep up the good work! |
|
|
||
| def main | ||
|
|
||
| puts "BIG BANG!" |
| user_response = gets.chomp.upcase | ||
|
|
||
|
|
||
| def upload_generic_list_of_planets(system) |
There was a problem hiding this comment.
Great work making all of these helper methods! They're great and perfect! In the future, we'll probably want these helper methods to be defined outside of the main method (so that they're "siblings" rather than being nested)
| end | ||
|
|
||
|
|
||
| def run_control_loop(system, response) |
There was a problem hiding this comment.
Hm, this method takes in response, but then immediately re-assigns it in the line after. Does this method actually need to take in a second parameter?
| def run_control_loop(system, response) | ||
|
|
||
| response = 0 | ||
| while response != 3 |
| @fun_fact = fun_fact | ||
| end | ||
|
|
||
| attr_reader :name, :color, :mass_kg, :distance_from_sun_km, :fun_fact |
There was a problem hiding this comment.
Just as a minor point: I think it may be preferable and more easily recognizable of these attr_readers were above the initialize method (and after the class Planet line)
| if checks_if_zero? | ||
| return "#{@name} is a #{@color} planet with a mass of #{@mass_kg}kg. It is #{@distance_from_sun_km}km away from the sun. Fun fact about #{@name}: #{@fun_fact}" | ||
| else | ||
| raise ArgumentError.new("#{@mass_kg == 0 ? 'Mass (kg)' : 'Distance from sun (km)'} must not equal zero") |
| if checks_if_zero? | ||
| return "#{@name} is a #{@color} planet with a mass of #{@mass_kg}kg. It is #{@distance_from_sun_km}km away from the sun. Fun fact about #{@name}: #{@fun_fact}" | ||
| else | ||
| raise ArgumentError.new("#{@mass_kg == 0 ? 'Mass (kg)' : 'Distance from sun (km)'} must not equal zero") |
There was a problem hiding this comment.
Based on the context of this error and the summary method, this is a completely ideological point, but I wonder if this ArgumentError should be raised or checked somewhere else in the code
|
|
||
| found_planet_summary = found_planet_summary.compact | ||
|
|
||
| # handles multiple planets with the same name |
There was a problem hiding this comment.
Great work handling this case!
I think that if you had more time, this logic would be a really good place for refactoring
| end | ||
|
|
||
| if found_planet_summary_string != "" | ||
| return found_planet_summary_string |
There was a problem hiding this comment.
Instead of returning a string, it probably would make more sense to return an instance of Planet. That being said, I think if you made that change now, a lot would have to be refactored in your other code!
| end | ||
|
|
||
| def saturn | ||
| return " |
| require_relative '../lib/main' | ||
| require_relative '../lib/solar_system' | ||
|
|
||
| describe "solar system project" do |
| describe "solar system project" do | ||
| describe "Planet class instance" do | ||
|
|
||
| it "returns false for mass that equals 0" do |
There was a problem hiding this comment.
nstead of naming this test as "returns false," we should rename it to "raises an argument error for mass that equals 0"
| solar_system.planets << Planet.new("earth", 1, 1, 1, 1) | ||
| found_planet = solar_system.find_planet_by_name("Krypton") | ||
|
|
||
| expect(found_planet).must_match "That planet is not in this solar system." |
There was a problem hiding this comment.
Just a nice FYI: In the future, we'll see that a lot of libraries in Ruby have a pattern that if there was no match, we get either nil or false or 0 or something like that, rather than an error string.
|
|
||
| end | ||
|
|
||
| it "measures the distance between two planets entered in reverse order" do |
There was a problem hiding this comment.
Nice tests!! This is an excellent test case to check for thoroughness!
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?