Class: Teepee::Scope
- Inherits:
-
Object
- Object
- Teepee::Scope
- Defined in:
- lib/teepee/scope.rb
Instance Attribute Summary collapse
-
#father ⇒ Object
Returns the value of attribute father.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #derive ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(father = nil) ⇒ Scope
constructor
A new instance of Scope.
- #keys ⇒ Object
- #orphan? ⇒ Boolean
- #scope_for(key) ⇒ Object
- #shadow?(key) ⇒ Boolean
Constructor Details
#initialize(father = nil) ⇒ Scope
Returns a new instance of Scope.
42 43 44 45 |
# File 'lib/teepee/scope.rb', line 42 def initialize father = nil @father = father @variables = Hash.new end |
Instance Attribute Details
#father ⇒ Object
Returns the value of attribute father.
40 41 42 |
# File 'lib/teepee/scope.rb', line 40 def father @father end |
#variables ⇒ Object
Returns the value of attribute variables.
40 41 42 |
# File 'lib/teepee/scope.rb', line 40 def variables @variables end |
Instance Method Details
#[](key) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/teepee/scope.rb', line 60 def [](key) if variables.has_key? key variables[key] elsif father father[key] end end |
#[]=(key, value) ⇒ Object
68 69 70 |
# File 'lib/teepee/scope.rb', line 68 def []=(key, value) variables[key] = value end |
#derive ⇒ Object
84 85 86 |
# File 'lib/teepee/scope.rb', line 84 def derive self.class.new self end |
#has_key?(key) ⇒ Boolean
55 56 57 58 |
# File 'lib/teepee/scope.rb', line 55 def has_key? key variables.has_key?(key) or (not orphan? and father.has_key?(key)) end |
#keys ⇒ Object
51 52 53 |
# File 'lib/teepee/scope.rb', line 51 def keys variables.keys end |
#orphan? ⇒ Boolean
47 48 49 |
# File 'lib/teepee/scope.rb', line 47 def orphan? not father or father.nil? end |
#scope_for(key) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/teepee/scope.rb', line 72 def scope_for key if variables.has_key? key self else father.scope_for key end end |
#shadow?(key) ⇒ Boolean
80 81 82 |
# File 'lib/teepee/scope.rb', line 80 def shadow? key has_key?(key) and not orphan? and father.has_key?(key) end |