Conversation
Solar SystemWhat We're Looking For
|
| @@ -0,0 +1,97 @@ | |||
| # Brittany Jones | |||
|
|
||
| class Planet | ||
| # Create reader methods to give a user access to read the instance variables. | ||
| attr_accessor :planet_hash |
There was a problem hiding this comment.
Code inside a class should be indented. Either use 1 tab or 2 spaces to indent code.
Also why make this a hash or an accessor?
By being a hash a user of Planet must know the structure of the hash and they keys.
By using attr_accessor you are giving users the ability to change @planet_hash. You probably don't want to do that.
Granted in this project it's a minor issue.
| #Create a SolarSystem class with an @planets instance variable. | ||
| #Make your SolarSystem class take an array of Planets instead of hashes. class will take an array of hashes, instead of hashes. | ||
| class SolarSystem | ||
| attr_accessor :planets |
There was a problem hiding this comment.
Similar issue with making this an acessor.
| attr_accessor :planets | ||
| def initialize | ||
| @planets = planets | ||
| @planets = [] |
There was a problem hiding this comment.
You are blanking out @planets so anything sent into initialize is erased.
Also your initialize method isn't getting sent a parameter.
You should have:
def initialize(planets)
@planets = planets
end|
|
||
| def add_planet(planet) | ||
| @planets.push(planet) | ||
| end |
| # Add planets to the @planets array. | ||
| def print | ||
| planets.each do |planet| | ||
| puts planet.name |
There was a problem hiding this comment.
You're doing what's called mixing roles here. Each class should focus on one role. SolarSystem should deal with storing planets and returning a list of planet names. Planet should store planet details and provide getter methods.
The main program's methods can deal with Input and output to the screen. That separation of roles can make things easier to reuse and modify.
| planet_choice = gets.chomp.capitalize | ||
| puts "\n------------------------------------------------------------\n\n" | ||
|
|
||
| case planet_choice |
There was a problem hiding this comment.
You're not using the SolarSystem instance!
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initializemethod in your class?SolarSystemused anArrayvs aHash.