forked from Ada-C5/Solar-System
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplanet.rb
More file actions
70 lines (49 loc) · 1.37 KB
/
planet.rb
File metadata and controls
70 lines (49 loc) · 1.37 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
class SolarSystem
attr_reader :planets
def intialize(planets)
planets.each do |planet|
@planets[planet.name] = planet
end
end
def add_planet(x)
@planets[x.name] = x
end
def remove_planet(planet_name)
@planets[planet_name] = nil
end
def name_of_planet(position)
planet_in_position = @planets[position]
planet_in_position.class #=> Planet
planet_in_position.colonized? #=> true or false
@planets[position].name
end
def distance_between(planet1, planet2)
end
end
class Planet
attr_reader :name, :earth_age
def initialize(options)
@name = options[:name]
@mass = options[:mass]
@rotation = options[:rotation]
@earth_age = options[:earth_age]
@distance = options[:distance]
@robots = options[:robots]
end
def colonized?
@robots == true
end
end
earth = Planet.new(name: "Earth", mass: 32598234, robots: true)
mars = Planet.new(name: "Earth", mass: 23455, robots: true)
solar_system = SolarSystem.new(name: "Our solar system", planets: [earth, mars])
venus = Planet.new(name: "Venus", mass: 2343284092384, robots: true)
planet_dog_food = Planet.new(name: "Dog Food", mass 0, robots: false)
solar_system.add_planet(venus)
solar_system.add_planet(planet_dog_food)
planets = {
"mercury" => Planet.new(),
"venus" => Planet.new()
}
choice = gets.chomp.downcase
planets[choice]