Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
48 changes: 48 additions & 0 deletions solar_system.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class SolarSystem

attr_accessor :name, :planets

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Watch your indentation here - you want to tab this in once

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I just added in my Planet class and solar system program. Sorry they were missing the first time around!


def initialize (planet_hash)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems like this is good - but without providing an example for how you're instantiating your SolarSystem, I'm not sure if it is "correct" or not

@name = planet_hash[:name]
@planets = []
end

def add_planet(planet)
@planets.push(planet)
end

def add_multiple_planets(planet_array)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is very good! You can also use a method called concat on an array, which will add a whole array of items:
@planets.concat(planet_array)

planet_array.each do |plan|
@planets.push(plan)
end
end

def about

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cool! I think the way you make this interactive to learn about each of the planets. I like the way that you use the count to dynamically display all of the different planets, and a while loop to continue throughout.

puts "Here are the planets in the #{@name} solar system:"
count = 1

@planets.each do |planet|
puts "#{count}. #{planet.name}"
count += 1
end
puts "#{count}. Exit"
puts "Which planet do you want to learn about?"
learn = gets.chomp.to_i
continue = true

while continue == true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since continue is a boolean value, you can change this like to: while continue

if learn < count
planets[learn-1].about
puts "What planet do you want to learn about next?"
learn = gets.chomp.to_i
elsif learn == count
puts "Goodbye!"
continue = false
else
puts "I am sorry. I don't know what you mean. Please enter in a number from 1 to #{count-1} to learn about a planet, or #{count} to exit"
learn = gets.chomp.to_i
end
end
end

end