forked from Ada-C6/CSV-Sample-Code
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolarSystem.rb
More file actions
Latest commit
36 lines (33 loc) · 766 Bytes
/
Copy pathSolarSystem.rb
File metadata and controls
36 lines (33 loc) · 766 Bytes
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
# SolarSystem.rb
classPlanet
attr_accessor:name,:distance,:mass,:moons,:diameter
definitialize(name,distance,mass,moons,diameter)
@name=name
@distance=distance
@mass=mass
@moons=moons
@diameter=diameter
end
defto_s()
return"Planet #{@name} has a mass of #{@mass}, #{@moons} moons, a diameter of #{@diameter} and is at a distance of #{@distance} from the sun."
end
end
classSolarSystem
definitialize(planets)
@planets=planets
end
defadd_Planet(planet)
@planets << planets
end
defadd_planets(planets)
planets.eachdo |planet|
@planets << planet
end
end
defto_s()
string=""
@planets.eachdo |planet|
string += planet.to_s() + "\n"
end
end
end