-
-
Save tildedave/725337 to your computer and use it in GitHub Desktop.
# scoping in ruby 1.8.7 | |
x = 0 | |
[1,2,3].each{|x| puts x} | |
puts x |
@tildedave, I agree the scoping behaviour of 1.8.7 is important to know about; the only point i took issue with was it being labelled "Ruby Scoping Behaviour"; esp. since this behaviour has been corrected in the stable and official 1.9 branch for 2 years now. :)
Ruby is in the process of getting a specification, and there is a draft one already released, see here: http://ruby-std.netlab.jp/draft_spec/download.html
Are you aware that Ruby 1.9 is almost a total reimplementation of Ruby? You appear to think it was a minor update.
Internally, Ruby 1.9 has very little in common with Ruby 1.8. In terms of features; Ruby 1.9 adds some major new features and cleans up a few inconsistencies and bugs - one of those bugs being the block variable scoping pointed out in this gist. Nonetheless Ruby 1.9 aims to be more or less 95% backwards compatible with Ruby 1.8 - which it has achieved.
Major releases are allowed to have breaking changes. Ruby 1.9 is a major release, it has breaking changes. In terms of 'expectation' - there were expected to be breaking changes. Once again: It is a Major Release.
Get over it. Everyone else has.
I definitely feel that 'weird' scoping behavior is important to know about, even if it has been fixed in later versions. Python 3 and Ruby 1.9.2 may be the most recent versions of their respective languages, but these are not the default versions on the most recent Ubuntu (for example), so there is still an awful lot of Python 2.6 and Ruby 1.8.7 code being written.
As there is no ruby specification (although https://github.com/rubyspec/rubyspec looks like an interesting project!), these implementation bugs are also bugs in the platonic Ruby language itself.
I have no political axe to grind against Ruby -- I like Ruby a lot! However, it is always interesting to me how other languages implement closures. This particular oddity is why you do a renaming on bound variables or some use mechanism like de bruijn indices in most closure implementations.