Class: MiniKraken::Core::Scope
- Inherits:
-
Object
- Object
- MiniKraken::Core::Scope
- Defined in:
- lib/mini_kraken/core/scope.rb
Overview
A scope is a name space that corresponds either to a specific delimited region in MiniKraken source code or to an activation record of a relation or a relation definition. It contains a map of names to the objects they name (e.g. logical var)
Instance Attribute Summary collapse
-
#defns ⇒ Hash{String => LogVar}
readonly
Mapping from user-defined name to related definition (say, a logical variable object).
-
#parent ⇒ Scope, NilClass
The parent (enclosing) scope.
Instance Method Summary collapse
-
#initialize(aParent = nil) ⇒ Scope
constructor
Construct a scope instance.
-
#insert(anEntry) ⇒ LogVar
Add a new logical variable to the scope.
-
#inspect ⇒ String
Returns a string with a human-readable representation of the object.
Constructor Details
#initialize(aParent = nil) ⇒ Scope
Construct a scope instance. TODO: extend with defrel and procedure
24 25 26 27 |
# File 'lib/mini_kraken/core/scope.rb', line 24 def initialize(aParent = nil) @parent = aParent @defns = {} end |
Instance Attribute Details
#defns ⇒ Hash{String => LogVar} (readonly)
Mapping from user-defined name to related definition
(say, a logical variable object)
19 20 21 |
# File 'lib/mini_kraken/core/scope.rb', line 19 def defns @defns end |
#parent ⇒ Scope, NilClass
The parent (enclosing) scope.
14 15 16 |
# File 'lib/mini_kraken/core/scope.rb', line 14 def parent @parent end |
Instance Method Details
#insert(anEntry) ⇒ LogVar
Add a new logical variable to the scope.
32 33 34 35 36 37 38 |
# File 'lib/mini_kraken/core/scope.rb', line 32 def insert(anEntry) e = validated_entry(anEntry) e.suffix = default_suffix if e.kind_of?(LogVar) defns[e.name] = e e end |
#inspect ⇒ String
Returns a string with a human-readable representation of the object.
42 43 44 |
# File 'lib/mini_kraken/core/scope.rb', line 42 def inspect +"#<#{self.class}:#{object_id.to_s(16)}>" end |