forked from Ada-C12/solar-system
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolar_system.rb
More file actions
53 lines (41 loc) · 1.03 KB
/
solar_system.rb
File metadata and controls
53 lines (41 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Solar-System : Classes Program
# Author: Farah Davoodi
# Email: farahdavoodi@gmail.com
# Date: August 19 2019
require_relative 'planet'
require 'pry'
class SolarSystem
attr_reader :star_name, :planets
def initialize(star_name)
@star_name = star_name
@planets = []
end
def add_planet(planet)
@planets << planet
end
def list_planets
planet_names = []
@planets.each_with_index do |planet,index|
planet_names << "#{index+1}. #{planet.name}"
end
return "Planets orbiting the #{star_name}:\n#{planet_names.join("\n")}"
end
def find_planet_by_name(planet_name)
@planets.each do |planet|
if planet_name.capitalize == planet.name
return planet
end
end
end
def planet_details
puts "What planet would you like to learn about?"
input = gets.chomp.capitalize
@planets.each do |planet|
if planet.name.include? (input)
return planet.summary
else
return "That planet does not exist"
end
end
end
end