From e8587f32728e0292c26da0909409586482926fb8 Mon Sep 17 00:00:00 2001 From: Desiree Date: Thu, 1 Oct 2015 11:23:27 -0700 Subject: [PATCH] Add solar system file --- solar-system.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 solar-system.rb diff --git a/solar-system.rb b/solar-system.rb new file mode 100644 index 00000000..f3fafa03 --- /dev/null +++ b/solar-system.rb @@ -0,0 +1,24 @@ +class SolarSystem + attr_accessor :planets, :name, :formation_year + + def initialize(name = "The Solar System", formation_year = 1234) + @name = name + @formation_year = formation_year + @planets = [] + end + + def add_planet(planet) + planet.solar_system = self + @planets.push(planet) + end + + def add_many_planets(planet_array) + planet_array.each { |planet| planet.solar_system = self } + @planets += planet_array + end + + def distance_between(planet_one, planet_two) + (planet_one.distance_from_sun - planet_two.distance_from_sun).abs + end + +end