Conversation
Solar SystemWhat We're Looking For
|
| num = 1 | ||
| @planets.each do |arr| | ||
| print "\n#{num}. #{arr.summary} ".cyan | ||
| num += 1 |
There was a problem hiding this comment.
I'm not convinced by the name of the block parameter here. arr is not very descriptive - it's not clear to the reader what type of thing you expect it to be. Calling it something like planet might be a better choice.
| @@ -0,0 +1,146 @@ | |||
| # Solar System project -create an object which contains a | |||
There was a problem hiding this comment.
Ruby files should be named using snake_case. So this one would be solar_system.rb.
The choice is somewhat arbitrary, but when we start working on group projects it will be important for all of us to be doing the same thing.
| case info | ||
| when "Earth" | ||
| puts earth.summary.green | ||
| when "Mercury" |
There was a problem hiding this comment.
This strategy of using a switch statement makes it difficult to add new planets. Could you do something like adding a method to SolarSystem to look up a planet by name? That would allow you to show info for user planets as well.
| end | ||
| # Add the planet to the SolarSystem class | ||
| planets.push(new_name = Planet.new(new_name, new_color, new_orbit, new_diameter, | ||
| new_distance)) |
There was a problem hiding this comment.
Adding the new planet to planets works, but it's not great form. The purpose of SolarSystem is to keep track of our list of planets, and it's a little confusing to modify the list directly from outside. Instead, you could define a method add_planet on SolarSystem that takes an instance of Planet and adds it to the list.
|
|
||
| planets.each do |x| | ||
| puts "#{num}. #{x.name}".cyan | ||
| num += 1 |
There was a problem hiding this comment.
This is another place where it might make sense to define a method on SolarSystem rather than accessing the list of planets directly.
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initializemethod in your class?SolarSystemused anArrayvs aHash.