3 ms·
You get the exact same name-resolution funniness in other languages, too. Like python, for example: >>> message = "Hello" >>> def f(): print message ...
by aston 18y ago
You get the exact same name-resolution funniness in other languages, too. Like python, for example:
>>> message = "Hello"
>>> def f(): print message
...
>>> message = "World"
>>> def g(): print message
...
>>> f()
World
>>> g()
World
This post is a nice example of misunderstanding scoping and/or closures (but probably both).
- raju 18y agoAgreed. True for Ruby too. Its important to remember how closures work, and what variables in the environment are being "closed" over. > message = 'test' > a = lambda { puts message } > message = 'test1' > b = lambda { puts message } > a.call test1 > b.call test1