Skip to content

Conversation

@Guribot
Copy link

@Guribot Guribot commented Aug 16, 2017

Solar System

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
What was the purpose of the initialize method in your class? To take the arguments (name, planets) and sort them into the corresponding instance variables (@name, @planets, @num_planets)
Describe an instance variable you used and what you used it for. @name is a string that is the name of the solar system in a way that is more output-friendly than a variable name (e.g. my_system vs. "My Solar System"). It's used when outputting the list of planets to the user.
Describe what the difference would be if your SolarSystem used an Array vs a Hash. Since it uses a hash of planets with names as the key, I am able to access the planets using a string of their names (e.g. my_system.planets('Mars'), but have to do more work to take user's number input to select a planet or print out a numbered list. If planets were stored in an array it would be easy to take number input and print a numbered list because of the index, but would be harder to call a planet by its name as a string.
Do you feel like you used consistent indentation throughout your code? Yes 👍

@droberts-sea
Copy link

Solar System

What We're Looking For

Feature Feedback
Created Custom Class with initialize method & instance variables. yes
Used an Array to store a list of planets in the SolarSystem class. yes
Readable code with consistent indentation. yes
Created a pull request with your name & the template questions answered. yes

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}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
end

This 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]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to write a method do do this work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants