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
- #to_a ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Variables
Returns a new instance of Variables.
11 12 13 14 |
# File 'lib/livetext/more.rb', line 11 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
16 17 18 |
# File 'lib/livetext/more.rb', line 16 def [](var) @vars[var.to_sym] end |
#[]=(var, value) ⇒ Object
20 21 22 |
# File 'lib/livetext/more.rb', line 20 def []=(var, value) @vars[var.to_sym] = value end |
#get(var) ⇒ Object
24 25 26 |
# File 'lib/livetext/more.rb', line 24 def get(var) @vars[var.to_sym] || "[#{var} is undefined]" end |
#set(var, value) ⇒ Object
28 29 30 |
# File 'lib/livetext/more.rb', line 28 def set(var, value) @vars[var.to_sym] = value.to_s end |
#setvars(pairs) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/livetext/more.rb', line 32 def setvars(pairs) pairs = pairs.to_a if pairs.is_a?(Hash) pairs.each do |var, value| api.setvar(var, value) end end |
#to_a ⇒ Object
39 40 41 |
# File 'lib/livetext/more.rb', line 39 def to_a @vars.to_a end |