Skip to content

Commit

Permalink
Specs for conditionally-assigned variables accessed in closure.
Browse files Browse the repository at this point in the history
See #4235
  • Loading branch information
headius committed Oct 20, 2016
1 parent 192ca18 commit 1dc3019
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/ruby/language/fixtures/variables.rb
Expand Up @@ -78,4 +78,8 @@ def self.without_parenthesis a
a
end
end

def self.false
false
end
end
24 changes: 24 additions & 0 deletions spec/ruby/language/variables_spec.rb
Expand Up @@ -750,3 +750,27 @@ module VariableSpecs
end
end
end

describe "A local variable assigned only within a conditional block" do
context "accessed from a later closure" do
it "is defined?" do
if VariablesSpecs.false
a = 1
end

1.times do
defined?(a).should == "local-variable"
end
end

it "is nil" do
if VariablesSpecs.false
a = 1
end

1.times do
a.inspect.should == "nil"
end
end
end
end

0 comments on commit 1dc3019

Please sign in to comment.