> On Jul 31, 2006, at 2:49 PM, Eric Armstrong wrote: > >> #!/usr/bin/env ruby >> >> repeat = 1 >> >> def run >> number_of_times = repeat >> ... >> Fails: undefined variable, "repeat" >> in first line of run method >> >> I would have sworn that this was the >> one that worked. >> I swear to the heavens that it was an innocent question? (But I look forward to a clear differentiation between closures and blocks from the thread that resulted.) > class, **def**, and module introduce a new scope > without closing over their enclosing scope. > That was the shift I needed in my mental model. Thanks much. I expected that behavior from class and module. I am quite surprised that it is true for def, as well. That surprise leads me to ask: Why? What is it that made that a good idea? thanks, all eric