From cea5394ea2dcfe670e22d0db18fd5549599a6423 Mon Sep 17 00:00:00 2001 From: Yordanos Date: Thu, 25 Feb 2016 10:51:34 -0800 Subject: [PATCH] These are my solar system class objects. --- Solar_system2.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Solar_system2.rb diff --git a/Solar_system2.rb b/Solar_system2.rb new file mode 100644 index 00000000..a993afdf --- /dev/null +++ b/Solar_system2.rb @@ -0,0 +1,42 @@ +# Solar System +# Let's make a planetary system! +# Baseline +# • Create a Planet class with a name attribute. +# • You should be able to instantiate a new Planet object with an associated name. +# Wave 1 +# Primary Requirements +# • Get creative! Give each instance of Planet at least five attributes. These could be diameters, mass, moons... whatever! +# • Allow these attributes to be set using a hash in initialize. +# You should be able to create many different planets with different properties, like Mercury, Venus, Earth, Mars, Jupiter, etc. + +class Solar_system + attr_accessor :planet1 + def initialize(planet) #planet array + if planet_ + @planet1 = planet[:planet1] + @planet2 = planet[:planet2] + @print_solar_system = print_solar_system + end + + def print_solar_system + puts @name + end + + def more_planets + @planet + +end + +class Planet #declare a class called Planet + attr_accessor :name , :moons, :fun #use attr_accessor attribute on instance name variable. + def initialize(planet_options) + @name = planet_options[:name] #string + @moons = planet_options[:moons] + @fun = planet_options[:fun] + end +end + +@earth = Planet.new(name: "Earth", moons: "1", fun: true) +@mars = Planet.new(name: "Mars", moons: "2", fun: true) + +@solar_system = Solar_system.new(planet1: @earth, planet2: @mars)