Class: RBelly::Runtime::ScopeChain
- Inherits:
-
Object
- Object
- RBelly::Runtime::ScopeChain
- Includes:
- JS
- Defined in:
- lib/rbelly/runtime/scope_chain.rb
Instance Method Summary collapse
- #<<(scope) ⇒ Object
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #has_property?(name) ⇒ Boolean
-
#initialize(scope = Scope.new) ⇒ ScopeChain
constructor
A new instance of ScopeChain.
- #new_scope(&block) ⇒ Object
- #pop ⇒ Object
- #return ⇒ Object
- #return=(value) ⇒ Object
- #returned? ⇒ Boolean
- #this ⇒ Object
Constructor Details
#initialize(scope = Scope.new) ⇒ ScopeChain
Returns a new instance of ScopeChain.
6 7 8 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 6 def initialize(scope = Scope.new) @chain = [GlobalObject.new] end |
Instance Method Details
#<<(scope) ⇒ Object
10 11 12 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 10 def <<(scope) @chain << scope end |
#[](name) ⇒ Object
21 22 23 24 25 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 21 def [](name) property = has_property?(name) return property if property @chain.last.properties[name] end |
#[]=(name, value) ⇒ Object
27 28 29 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 27 def []=(name, value) @chain.last.properties[name] = value end |
#has_property?(name) ⇒ Boolean
14 15 16 17 18 19 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 14 def has_property?(name) scope = @chain.reverse.find { |x| x.has_property?(name) } scope ? scope[name] : nil end |
#new_scope(&block) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 39 def new_scope(&block) @chain << Scope.new result = yield(self) @chain.pop result end |
#pop ⇒ Object
31 32 33 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 31 def pop @chain.pop end |
#return ⇒ Object
50 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 50 def return; @chain.last.return; end |
#return=(value) ⇒ Object
46 47 48 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 46 def return=(value) @chain.last.return = value end |
#returned? ⇒ Boolean
52 53 54 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 52 def returned? @chain.last.returned? end |
#this ⇒ Object
35 36 37 |
# File 'lib/rbelly/runtime/scope_chain.rb', line 35 def this @chain.last end |