forked from RubyoffRails/recipe-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.rb
39 lines (32 loc) · 997 Bytes
/
train.rb
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
# Change our recipe hash into a hash that that describes a Train.
# It should have
# a current city, a number of engines, a number of cars, and a caboose.
# output the train formatted nicely.
# Create a passenger Struct that has a name and a train (from above)
def print_train train, consists
puts "\nTrain"
puts "\tCurrent City: #{train[:current_city]}"
puts "\tConsists of:"
train[:consists].each do |key,value|
puts "\t* #{key}: #{value}"
end
end
#version 1
consists = {}
consists[:engines] = 3
consists[:cars] = 2
consists[:cabose] = true
train = {}
train[:current_city] = "Minion Town"
train[:consists] = consists
#version 2
consists2 = {engines: 1, cars: 4, cabose: false}
train2 = {current_city: "Minion Town Too" ,consists: consists2}
train2.each do |key,value|
puts "#{key} #{value}"
end
print_train(train,consists)
print_train(train2,consists2)
Passenger = Struct.new(:name, :train)
passenger = Passenger.new("Papoy", train)
# puts passenger # just checking it's not a dud