-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sockets - Grace #40
base: master
Are you sure you want to change the base?
Sockets - Grace #40
Conversation
… when the user requests. i'm reading ahead here, so returning to the methods...
…ed methods on solar_system.rb... I think
Solar SystemWhat We're Looking For
This is a good start - your code is well-organized, and it's clear that the learning goals around creating and working with classes were met. Unfortunately some of the functionality of this app is broken as-submitted. In both cases all that was needed to fix it was a small change, indicating that you probably changed things at the last minute and submitted without testing it out. I'm also seeing some confusion around the difference between That being said, I'm not too concerned by what I see here. Make sure to test your code before you turn it in, and keep up the hard work! |
def find_planet_by_name(planet) | ||
@planets.each do |planet| | ||
if planet.name == name.capitalize | ||
return planet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code has a bug! Your parameter (which should be the name of a planet) is called planet
, but you override this on line 47 by using the same name for your iteration parameter. The on line 48, you look for the variable name
, which doesn't exist.
Probably the parameter should be called name
, not planet
. Making this change seems to fix the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dan, thank you for your feedback! I will take a look at this over the weekend and refactor.
when input == "3" | ||
solar_system.add_a_planet | ||
puts "\n...Entered into system. Thank You." | ||
when input == "4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option 3 does not work - the method on SolarSystem
is get_info_new_planet
, not add_a_planet
.
def get_info_new_planet | ||
print "\nWhat is your new Planet's name?" | ||
planet_name = gets.chomp.to_s | ||
print "\nWhat is #{planet_name}'s color?" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have a lot of code that interacts with the user here, which makes me think this method might fit better in main.rb
.
planet1 = get_planet_name | ||
planet2 = get_planet_name | ||
distance = planet1.distance_from_sun_km - planet2.distance_from_sun_km | ||
puts "\nDistance between #{planet1.name} and #{planet2.name}: #{distance.abs} km." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should return a number here instead of puts
ing the result. Then whoever called this method could use that number. For example, if someone wanted to write a method to find the two planets that are closest together, a number would be much more valuable than this string.
def get_planet_name | ||
print "\nEnter planet name: " | ||
planet = gets.chomp.to_s | ||
return find_planet_by_name(planet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method also might fit better in main.rb
Solar System
Congratulations! You're submitting your assignment.
Comprehension Questions
initialize
method run? What does it do?Hash
instead of an instance of a class?SolarSystem
class used aHash
instead of anArray
to store the list of planets?require
statements? Which files neededrequire
s, and which did not? What is the pattern?