codebar / tutorials

🗒 codebar's tutorials
http://tutorials.codebar.io/
257 stars 241 forks source link

Remove bonus section in Ruby Lesson 2, Exercise 1 #397

Closed koddsson closed 5 years ago

koddsson commented 6 years ago

I was working on this lesson with a student today and this bonus section doesn't seem to make a lot of sense to me.

The section explains that you can use the ||= operator to set a value to a variable only if it's value is nil. The issue is that the student is most likely to do something like this:

number_of_turns = gets.to_i

which can never be nil since if you just hit Enter it will result in number_of_turns being set to 0.

Even if the student did something like:

number_of_turns = gets

with the intention of converting it to a integer later it would still not be enough to use the ||= operator since number_of_turns will be set to a empty string when the user hits Enter at the turns prompt.

This PR removes the section completely rather then trying to rewrite it. If we really want to keep it around we could talk about the NaN results and error that is raised when a user hits Enter on the turns prompt and suggestions on how to fix it.