Class: Vissen::Parameterized::Scope
- Inherits:
-
Object
- Object
- Vissen::Parameterized::Scope
- Defined in:
- lib/vissen/parameterized/scope.rb
Overview
The scope exists to protect parameterized objects from being bound to parameters with a different lifetime than their own.
Each scope is bound to a ‘Conditional` and as long as it, as well as the conditionals of all the parents return false, the scope is considered to be alive.
By checking that one scope is included in another, it is possible to guarantee that values belonging to the first scope are safe to use.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#parent ⇒ Scope
readonly
The parent of this scope.
Instance Method Summary collapse
-
#alive? ⇒ false, true
The inverse of ‘#dead?`.
-
#create_scope(conditional) ⇒ Scope
Creates a new scope that is a direct descendent of this one.
-
#dead? ⇒ true, false
A scope is considered dead once its conditional returns true, or if the parent scope is also dead.
-
#include?(obj) ⇒ true, false
(also: #===)
Checks if the given object is included, either in this scope or in any of the parent scopes.
-
#include_scope?(other) ⇒ true
Checks if the given scope is included in the scope hierarchy of this one.
-
#kill! ⇒ nil
Forces the conditional to return true, irregardless of its actual state.
Instance Attribute Details
#parent ⇒ Scope (readonly)
Returns the parent of this scope.
16 17 18 |
# File 'lib/vissen/parameterized/scope.rb', line 16 def parent @parent end |
Instance Method Details
#alive? ⇒ false, true
The inverse of ‘#dead?`
33 34 35 |
# File 'lib/vissen/parameterized/scope.rb', line 33 def alive? !dead? end |
#create_scope(conditional) ⇒ Scope
Creates a new scope that is a direct descendent of this one.
61 62 63 |
# File 'lib/vissen/parameterized/scope.rb', line 61 def create_scope(conditional) Scope.new self, conditional end |
#dead? ⇒ true, false
A scope is considered dead once its conditional returns true, or if the parent scope is also dead.
23 24 25 |
# File 'lib/vissen/parameterized/scope.rb', line 23 def dead? @conditional.met? || parent.dead? end |
#include?(obj) ⇒ true, false Also known as: ===
Checks if the given object is included, either in this scope or in any of the parent scopes.
50 51 52 |
# File 'lib/vissen/parameterized/scope.rb', line 50 def include?(obj) include_scope? obj.scope end |
#include_scope?(other) ⇒ true
Checks if the given scope is included in the scope hierarchy of this one.
71 72 73 |
# File 'lib/vissen/parameterized/scope.rb', line 71 def include_scope?(other) equal?(other) || @parent.include_scope?(other) end |
#kill! ⇒ nil
Forces the conditional to return true, irregardless of its actual state.
40 41 42 |
# File 'lib/vissen/parameterized/scope.rb', line 40 def kill! @conditional.force! end |