-
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
Danielle Metzner - Solar System #36
base: master
Are you sure you want to change the base?
Conversation
…tance are greater than 0
…re entered into distance or mass parameters
…gs instead of integers or floats
…ting methods for the prompts that are repeated over and over
Solar SystemWhat We're Looking For
|
#Calculates the distance between two planets | ||
def distance_between(planet1, planet2) | ||
distance = find_planet_by_name(planet2).distance_from_sun_km - find_planet_by_name(planet1).distance_from_sun_km | ||
return distance.abs |
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.
nice 🥇
@planets = [] | ||
end | ||
|
||
attr_reader :star_name, :planets |
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.
It's convention to put the attr_reader
and attr_accessor
etc above initialize
and below the class name
require_relative 'planet' | ||
require_relative 'solar_system' | ||
|
||
def main |
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 is just crying to be broken into smaller methods!
|
||
#Finds the planet with the same name and returns the planet object | ||
def find_planet_by_name(planet_name) | ||
found_planet = @planets.select {|planet| planet.name.downcase == planet_name.downcase} |
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 could also use .find
instead of .select
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?