Leaves - Cloudy#50
Conversation
…d main.rb and the new planets
Solar SystemWhat We're Looking For
|
| @@ -0,0 +1,74 @@ | |||
| require_relative 'planet' | |||
There was a problem hiding this comment.
Fun fact, since Solar_system.rb requires 'planet', this is not necessary!
| puts "Do you want to play again? Yes or No?" | ||
| answer = gets.chomp | ||
| if answer == "yes" | ||
| main_menu |
There was a problem hiding this comment.
This method call turns this from a loop into a recursive call! Don't do this unless you have a very good reason.
In other words, avoid the situation where either:
method_acallsmethod_a- or
method_acallsmethod_bcallsmethod_a
|
|
||
| user_input = "y" | ||
|
|
||
| while user_input == "y" |
There was a problem hiding this comment.
user_input never changes, Which is not a great way to write a while loop. You rely on a break keyword at the end of this section to end the loop, rather than changing the value of user_input. In other words, what you've written is equivalent to:
while true
if [some exit logic]
break
end
end|
|
||
| def list_planets | ||
| list = "\nPlanets orbiting #{@star_name}:" | ||
| @planets.each_with_index do |planet, index| |
There was a problem hiding this comment.
Your code is really squished together vertically. I like to use new lines between separate "thoughts" in my code to make it easier to digest.
| list += "\n#{index + 1}. #{planet.name}" | ||
| end | ||
| return list | ||
| main |
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?