From 96c24a801161099266048d8783e572c77f22ee8e Mon Sep 17 00:00:00 2001 From: shell Date: Fri, 21 Mar 2014 09:31:40 -0700 Subject: [PATCH 1/2] Created a hash that describes a Train (and a passenger Struct) --- train.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 train.rb diff --git a/train.rb b/train.rb new file mode 100644 index 0000000..3c02a88 --- /dev/null +++ b/train.rb @@ -0,0 +1,33 @@ +# 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 + +consists = {} +consists[:engines] = 3 +consists[:cars] = 2 +consists[:cabose] = true + +train = {} +train[:current_city] = "Minion Town" +train[:consists] = consists + +consists2 = {engines: 3, cars: 2, cabose: true} +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) \ No newline at end of file From be7433f3adb9c1b2ba49eabd085f61295c951741 Mon Sep 17 00:00:00 2001 From: shell Date: Fri, 21 Mar 2014 09:42:54 -0700 Subject: [PATCH 2/2] Saved passenger Struct before commit --- train.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/train.rb b/train.rb index 3c02a88..e07a149 100644 --- a/train.rb +++ b/train.rb @@ -13,7 +13,7 @@ def print_train train, consists puts "\t* #{key}: #{value}" end end - +#version 1 consists = {} consists[:engines] = 3 consists[:cars] = 2 @@ -23,11 +23,17 @@ def print_train train, consists train[:current_city] = "Minion Town" train[:consists] = consists -consists2 = {engines: 3, cars: 2, cabose: true} +#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) \ No newline at end of file +print_train(train2,consists2) + +Passenger = Struct.new(:name, :train) +passenger = Passenger.new("Papoy", train) + +# puts passenger # just checking it's not a dud \ No newline at end of file