forked from Ada-C9/Solar-System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolar_system_wave2.rb
More file actions
76 lines (58 loc) · 1.58 KB
/
solar_system_wave2.rb
File metadata and controls
76 lines (58 loc) · 1.58 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Create a SolarSystem class with an @planets instance variable.
# Create an initialize method which should take a collection of planet names and store them in an @planets instance variable.
# Create a method that adds a planet to the list (not using user input).
# Create a method which will return, not print, a list of the planets as a String.
# Write code to test your SolarSystem
# Modify SolarSystem's initialize method to take a list of hashes where each planet is sent as a hash with at least 5 attributes.
# Define the class
class SolarSystem
def initialize(planets)
@planets = planets
end
attr_reader :planets
def puts_self
puts self
end
def self.planets
return @planets
end
def planet
puts
end
arr_planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
@planets = ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
end
class Planet
attr_accessor :name
attr_accessor :order
attr_accessor :radius
attr_accessor :moons
def initialize(name, order, radius, moons)
@name = name
@order = order
@radius = radius
@moons = moons
end
def puts_self
puts self
end
def self.name
return @name
end
# instance method
def summary
return " #{order}. #{name} - Radius: #{radius}km. Number of Moons: #{moons}."
end
def self.summary
return @summary
end
end
planet_arr = [
Planet.new("Mercury", 1, 2440 , 0),
Planet.new("Venus", 2, 6052 , 0),
Planet.new("Earth", 3, 6371 ,1)
]
puts
planet_arr.each do |i|
puts i.summary
end