Create Pipes - Kate Evans-Spitzer - Solar System.rb#47
Create Pipes - Kate Evans-Spitzer - Solar System.rb#47Guribot wants to merge 1 commit intoAda-C8:masterfrom
Conversation
Solar SystemWhat We're Looking For
Great work overall! I've got a few nitpicks pointed out below, but in general I'm quite happy with what you've submitted. |
| def initialize(name, planets) | ||
| @system_name = name.to_s | ||
| @planets = {} | ||
| planets.each {|new_planet| @planets[new_planet.name] = new_planet} |
There was a problem hiding this comment.
Style nitpick: in general, you should expand your each loops into multiple lines. So in this case that would be:
planets.each do |new_planet|
@planets[new_planet.name] = new_planet
end|
|
||
| def add_planet(*planet) # Adds one or more Planet objects to solar system | ||
| planet.each {|new_planet| @planets[new_planet.name] = new_planet} | ||
| @num_planets = @planets.length |
There was a problem hiding this comment.
It's interesting to me that you stored the number of planets in a variable. As we can see, you have to remember to update the value every time the set of planets changes. This isn't necessarily a bad thing, but it's an extra piece for you the developer to remember. For example, it would be easy to write a remove_planet method and forget to update the count.
A cleaner way to do it might be to build an instance method that provides direct access to @planets.length, something like:
def num_planets
return @planets.length
endThis has the same effect, without requiring you to keep track of an extra thing.
| def distance_between(first, second) | ||
|
|
||
| if first.class == String # DRY??? | ||
| first = @planets[first] |
There was a problem hiding this comment.
You might be able to write a method do do this work.
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initializemethod in your class?SolarSystemused anArrayvs aHash.