Skip to content

Commit

Permalink
Add Scope#root, returning the top scope.
Browse files Browse the repository at this point in the history
  • Loading branch information
blambeau committed Jun 13, 2012
1 parent 4dcfda7 commit 7d10b33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/wlang/scope.rb
Expand Up @@ -30,6 +30,10 @@ def self.chain(scopes)
}
end

def root
parent.nil? ? self : parent.root
end

def push(x)
Scope.coerce(x, self)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/test_scope.rb
Expand Up @@ -28,6 +28,13 @@ module WLang
end
end

it 'gives access to the root' do
scope.root.should eq(Scope.null)
scope.with(:other => "World2") do |s|
s.root.should eq(Scope.null)
end
end

it 'evaluates `self` accurately' do
scope.evaluate(:self).should eq(:who => "World")
end
Expand Down

0 comments on commit 7d10b33

Please sign in to comment.