From b9c553f6cd11f422e07933be936f6e7cd079f159 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 23 Jun 2024 16:16:36 +0200 Subject: [PATCH] Add test for for-loop with global variable as iterator name --- language/for_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/language/for_spec.rb b/language/for_spec.rb index fb1218140..1d0750623 100644 --- a/language/for_spec.rb +++ b/language/for_spec.rb @@ -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