From 1fc99a697d468c10f444e4ebd466036cf08721f1 Mon Sep 17 00:00:00 2001 From: dnourie2 Date: Sat, 3 May 2014 17:14:21 -0700 Subject: [PATCH 1/2] Changed the Recipe to Train and Passenger information. --- recipe.rb | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/recipe.rb b/recipe.rb index d4b2000..7677535 100644 --- a/recipe.rb +++ b/recipe.rb @@ -1,17 +1,23 @@ -ingredients = {} -ingredients[:avocados] = 4 -ingredients[:jalapenos] = 2 - -Recipe = Struct.new(:ingredients, :method) +Train = Struct.new(:city, :engines, :cars, :caboose) do + def info + puts "This train is going to #{city}, and it has #{engines} engines, #{cars} cars, and #{caboose} caboose." + end +end -recipe = Recipe.new( {avacados: 4, jalapenos: 2}, ["Peel / Slice Avocados", "Chop jalapenos into small dice"]) +amtrack = Train.new("San Jose", 2, 8, 1) -puts "ingredients" -recipe.ingredients.each do |key, value| - puts "* #{key}: #{value}" +Passenger = Struct.new(:name, :train) do + def trip + puts "#{name} is riding the #{train} while on vacation." + end end -puts "\nMethod" -recipe.method.each_with_index do |step, index| - puts "#{index+1}. #{step}" -end \ No newline at end of file +first_passenger = Passenger.new("Sharon", "amtrack") +first_passenger.trip +amtrack.info +#amtrack.each_pair {|name, value| puts("About the train: #{name} => #{value}")} +#The above line is not necessary, but I thought it was cool:-) + + + + From e54f9fca2eba1b174d5a0461395e5f516f4bf6b2 Mon Sep 17 00:00:00 2001 From: dnourie2 Date: Mon, 5 May 2014 19:05:13 -0700 Subject: [PATCH 2/2] Removed puts from class def, and added it where I call the method. --- recipe.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/recipe.rb b/recipe.rb index 7677535..a0bee81 100644 --- a/recipe.rb +++ b/recipe.rb @@ -1,6 +1,6 @@ Train = Struct.new(:city, :engines, :cars, :caboose) do def info - puts "This train is going to #{city}, and it has #{engines} engines, #{cars} cars, and #{caboose} caboose." + "This train is going to #{city}, and it has #{engines} engines, #{cars} cars, and #{caboose} caboose." end end @@ -8,13 +8,13 @@ def info Passenger = Struct.new(:name, :train) do def trip - puts "#{name} is riding the #{train} while on vacation." + "#{name} is riding the #{train} while on vacation." end end first_passenger = Passenger.new("Sharon", "amtrack") -first_passenger.trip -amtrack.info +puts first_passenger.trip +puts amtrack.info #amtrack.each_pair {|name, value| puts("About the train: #{name} => #{value}")} #The above line is not necessary, but I thought it was cool:-)