Class: Verneuil::Scope
- Inherits:
-
Object
- Object
- Verneuil::Scope
- Defined in:
- lib/verneuil/scope.rb
Overview
The execution scope for verneuil code. This maintains a link to the external context given when starting the process to be able to delegate method calls to user code.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #defined?(name) ⇒ Boolean
- #enter ⇒ Object
-
#initialize(context, local_vars = {}, parent = nil) ⇒ Scope
constructor
A new instance of Scope.
- #inspect ⇒ Object
- #lvar_exist?(name) ⇒ Boolean
- #lvar_get(name) ⇒ Object
- #lvar_set(name, value) ⇒ Object
- #method_call(name, *args) ⇒ Object
Constructor Details
#initialize(context, local_vars = {}, parent = nil) ⇒ Scope
Returns a new instance of Scope.
9 10 11 12 13 |
# File 'lib/verneuil/scope.rb', line 9 def initialize(context, local_vars={}, parent=nil) @local_vars = local_vars @context = context @parent = parent end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/verneuil/scope.rb', line 7 def context @context end |
Instance Method Details
#defined?(name) ⇒ Boolean
30 31 32 33 34 |
# File 'lib/verneuil/scope.rb', line 30 def defined?(name) return 'local-variable' if lvar_exist?(name) return 'method' if context.respond_to?(name) nil end |
#enter ⇒ Object
15 16 17 |
# File 'lib/verneuil/scope.rb', line 15 def enter Verneuil::Scope.new(context, {}, nil) end |
#inspect ⇒ Object
40 41 42 43 |
# File 'lib/verneuil/scope.rb', line 40 def inspect "scope(#{@local_vars.inspect[2..-2]})" + (@parent ? "-> #{@parent.inspect}" : '') end |
#lvar_exist?(name) ⇒ Boolean
19 20 21 |
# File 'lib/verneuil/scope.rb', line 19 def lvar_exist?(name) @local_vars.has_key?(name) end |
#lvar_get(name) ⇒ Object
22 23 24 25 26 |
# File 'lib/verneuil/scope.rb', line 22 def lvar_get(name) raise Verneuil::NameError, "No such local variable #{name.inspect}." \ unless @local_vars.has_key?(name) @local_vars[name] end |
#lvar_set(name, value) ⇒ Object
27 28 29 |
# File 'lib/verneuil/scope.rb', line 27 def lvar_set(name, value) @local_vars[name] = value end |
#method_call(name, *args) ⇒ Object
36 37 38 |
# File 'lib/verneuil/scope.rb', line 36 def method_call(name, *args) context.send(name, *args) end |