Class: Livetext::Variables
Instance Attribute Summary collapse
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #[](var) ⇒ Object
- #[]=(var, value) ⇒ Object
- #get(var) ⇒ Object
-
#initialize(hash = {}) ⇒ Variables
constructor
A new instance of Variables.
- #set(var, value) ⇒ Object
- #setvars(pairs) ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Variables
Returns a new instance of Variables.
10 11 12 13 |
# File 'lib/livetext/more.rb', line 10 def initialize(hash = {}) @vars = {} hash.each_pair {|k, v| @vars[k.to_sym] = v } end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
9 10 11 |
# File 'lib/livetext/more.rb', line 9 def vars @vars end |
Instance Method Details
#[](var) ⇒ Object
15 16 17 |
# File 'lib/livetext/more.rb', line 15 def [](var) @vars[var.to_sym] end |
#[]=(var, value) ⇒ Object
19 20 21 |
# File 'lib/livetext/more.rb', line 19 def []=(var, value) @vars[var.to_sym] = value end |
#get(var) ⇒ Object
23 24 25 |
# File 'lib/livetext/more.rb', line 23 def get(var) @vars[var.to_sym] || "[#{var} is undefined]" end |
#set(var, value) ⇒ Object
27 28 29 |
# File 'lib/livetext/more.rb', line 27 def set(var, value) @vars[var.to_sym] = value.to_s end |
#setvars(pairs) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/livetext/more.rb', line 31 def setvars(pairs) pairs = pairs.to_a if pairs.is_a?(Hash) pairs.each do |var, value| api.setvar(var, value) end end |