-
Notifications
You must be signed in to change notification settings - Fork 18
recipe-hash exercise complete #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| itinerary = %w'Vancouver Calgary Edmonton Winnipeg Toronto' | ||
| train = {} | ||
| train[:engines] = 1 | ||
| train[:cars] = 20 | ||
| train[:caboose] = "Great Western Trail" | ||
| train[:cities] = itinerary | ||
| train[:current_city] = "Edmonton" | ||
|
|
||
| Passenger = Struct.new(:name, :train) | ||
| passenger = Passenger.new( "Simon Jones", train) | ||
|
|
||
| puts "Passenger: #{passenger.name}" | ||
|
|
||
| puts "\nTrain details" | ||
| passenger.train.each do |key, value| | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like what you did here, a LOT. yay! One thing I'd rather see in a loop than an if/else is to handle each condition as a separate section of code. It would make extracting later easier. intents:
So maybe: puts "\nItinerary"
passenger.train[:cities].each do |city|
print " * #{city}"
print " << CURRENT CITY" if city == passenger.train[:current_city]
puts "\n"
end
puts "\nTrain details"
passenger.train.reject{ |k| k ==:cities }.each do |key, value|
puts " -- #{key}: #{value}"
endIt's a little longer, but you can (arguably), tell what the intent is. |
||
| if key == :cities | ||
| puts "\nItinerary" | ||
| value.each do |city| | ||
| print " * #{city}" | ||
| print " << CURRENT CITY" if city == passenger.train[:current_city] | ||
| puts "\n" | ||
| end | ||
| else | ||
| puts " -- #{key}: #{value}" if key != :current_city | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,15 @@ | ||
| ingredients = {} | ||
| ingredients[:avocados] = 4 | ||
| ingredients[:jalapenos] = 2 | ||
| train = {} | ||
| train[:engines] = 1 | ||
| train[:cars] = 20 | ||
| train[:caboose] = "Great Western Trail" | ||
| train[:city] = "Edmonton" | ||
|
|
||
| Recipe = Struct.new(:ingredients, :method) | ||
| Passenger = Struct.new(:name, :train) | ||
| passenger = Passenger.new( "Simon Jones", train) | ||
|
|
||
| recipe = Recipe.new( {avacados: 4, jalapenos: 2}, ["Peel / Slice Avocados", "Chop jalapenos into small dice"]) | ||
| puts "Passenger: #{passenger.name}" | ||
|
|
||
| puts "ingredients" | ||
| recipe.ingredients.each do |key, value| | ||
| puts "* #{key}: #{value}" | ||
| puts "\nTrain details" | ||
| passenger.train.each do |key, value| | ||
| puts " -- #{key}: #{value}" | ||
| end | ||
|
|
||
| puts "\nMethod" | ||
| recipe.method.each_with_index do |step, index| | ||
| puts "#{index+1}. #{step}" | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great use of
%w!