Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for for-loop with global variable as iterator name #1163

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

@andrykonchin andrykonchin Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the only not test case left is using an attribute, e.g.

class A
  attr_accessor :foo
end
a = A.new

for a.foo in []
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: #1166


# 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