Class: Rtml::HighLevel::VariableManager
- Inherits:
-
Object
- Object
- Rtml::HighLevel::VariableManager
- Defined in:
- lib/rtml/high_level/variable_manager.rb
Instance Attribute Summary collapse
-
#screen ⇒ Object
Returns the value of attribute screen.
Instance Method Summary collapse
- #[](variable_name) ⇒ Object
- #[]=(target, other) ⇒ Object
-
#initialize ⇒ VariableManager
constructor
A new instance of VariableManager.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ VariableManager
Returns a new instance of VariableManager.
4 5 6 |
# File 'lib/rtml/high_level/variable_manager.rb', line 4 def initialize() @vars = HashWithIndifferentAccess.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/rtml/high_level/variable_manager.rb', line 26 def method_missing(name, *args, &block) if args.empty? && !block_given? self.send("[]", name) elsif name.to_s[-1] == ?= && args.length == 1 && !block_given? self.send("[]=", name.to_s[0...-1], *args) else super end end |
Instance Attribute Details
#screen ⇒ Object
Returns the value of attribute screen.
2 3 4 |
# File 'lib/rtml/high_level/variable_manager.rb', line 2 def screen @screen end |
Instance Method Details
#[](variable_name) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/rtml/high_level/variable_manager.rb', line 8 def [](variable_name) variable_name = variable_name.to_s vardec = screen.document.variable_definitions.select { |i| i['name'] == variable_name } vardec = vardec.collect { |i| i['name'] }.first raise Rtml::Errors::MissingVariableError, "Could not find a TML variable named #{variable_name}. "+ "Did you forget to declare it?" unless vardec @vars[variable_name] ||= Rtml::HighLevel::ManagedVariable.new(variable_name) end |
#[]=(target, other) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/rtml/high_level/variable_manager.rb', line 17 def []=(target, other) case other when Rtml::HighLevel::ManagedVariable screen.set self[target].name => "tmlvar:#{other.name}" else screen.set self[target].name => other end end |