Skip to content

Commit

Permalink
Merge pull request #1163 from herwinw/for_target_global_variable
Browse files Browse the repository at this point in the history
Add test for for-loop with global variable as iterator name
  • Loading branch information
andrykonchin authored Jun 24, 2024
2 parents 13a7ef2 + b9c553f commit 2cde58f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions language/for_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ class OFor
end
end

it "allows a global variable as an iterator name" do
old_global_var = $var
m = [1,2,3]
n = 0
for $var in m
n += 1
end
$var.should == 3
n.should == 3
$var = old_global_var
end

# 1.9 behaviour verified by nobu in
# http://redmine.ruby-lang.org/issues/show/2053
it "yields only as many values as there are arguments" do
Expand Down

0 comments on commit 2cde58f

Please sign in to comment.