Module: Lich::Common::UserVars
- Defined in:
- documented/common/uservars.rb
Overview
Provides a compatibility layer and additional convenience methods for Vars. This module delegates most operations to Vars while providing legacy method support and some additional functionality like comma-separated list management.
Provides methods for managing user-specific variables This module acts as a compatibility layer for variable management.
Class Method Summary collapse
-
.[](name) ⇒ Object?
Retrieves a variable value by name (bracket notation).
-
.[]=(name, val) ⇒ Object?
Sets a variable value by name (bracket notation).
-
.add(var_name, value, _t = nil) ⇒ String
Adds a value to a comma-separated list variable.
-
.change(var_name, value, _t = nil) ⇒ Object
Sets a variable to a new value.
-
.delete(var_name, _t = nil) ⇒ nil
Deletes a variable by setting it to nil.
-
.list ⇒ Hash
Returns a duplicate of all variables as a Hash.
-
.list_char ⇒ Hash
Returns a duplicate of all character-specific variables as a Hash.
-
.list_global ⇒ Array
deprecated
Deprecated.
Use #list or #list_char instead
-
.method_missing(method_name, *args) ⇒ Object?
Handles dynamic method calls for variable access.
-
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Declares that method_missing can respond to valid Ruby method names.
Class Method Details
.[](name) ⇒ Object?
Retrieves a variable value by name (bracket notation)
Delegates to Vars.[].
45 46 47 |
# File 'documented/common/uservars.rb', line 45 def UserVars.[](name) Vars[name] end |
.[]=(name, val) ⇒ Object?
Sets a variable value by name (bracket notation)
Delegates to Vars.[]=.
57 58 59 |
# File 'documented/common/uservars.rb', line 57 def UserVars.[]=(name, val) Vars[name] = val end |
.add(var_name, value, _t = nil) ⇒ String
This method assumes the variable contains a comma-separated string. If the variable contains a different data type, this will raise an error.
Adds a value to a comma-separated list variable
If the variable contains a comma-separated string, this method appends the new value to the list. If the variable doesn’t exist or is nil, it creates a new single-value string.
The third parameter is ignored and exists for legacy API compatibility.
126 127 128 129 130 131 132 133 |
# File 'documented/common/uservars.rb', line 126 def UserVars.add(var_name, value, _t = nil) current = Vars[var_name] if current.nil? || current.empty? Vars[var_name] = value.to_s else Vars[var_name] = current.to_s.split(', ').push(value.to_s).join(', ') end end |
.change(var_name, value, _t = nil) ⇒ Object
Sets a variable to a new value
This is a convenience method for backward compatibility. The third parameter is ignored and exists for legacy API compatibility.
102 103 104 |
# File 'documented/common/uservars.rb', line 102 def UserVars.change(var_name, value, _t = nil) Vars[var_name] = value end |
.delete(var_name, _t = nil) ⇒ nil
Deletes a variable by setting it to nil
This is a convenience method for backward compatibility. The second parameter is ignored and exists for legacy API compatibility.
147 148 149 |
# File 'documented/common/uservars.rb', line 147 def UserVars.delete(var_name, _t = nil) Vars[var_name] = nil end |
.list ⇒ Hash
Returns a duplicate of all variables as a Hash
Delegates to Vars.list.
34 35 36 |
# File 'documented/common/uservars.rb', line 34 def UserVars.list Vars.list end |
.list_char ⇒ Hash
Returns a duplicate of all character-specific variables as a Hash
This is an alias for #list provided for backward compatibility.
174 175 176 |
# File 'documented/common/uservars.rb', line 174 def UserVars.list_char Vars.list end |
.list_global ⇒ Array
Use #list or #list_char instead
Returns an empty array (legacy global variables are not supported)
This method exists for backward compatibility with older code that expected separate global and character-specific variables. In the current implementation, all variables are character-specific.
160 161 162 |
# File 'documented/common/uservars.rb', line 160 def UserVars.list_global Array.new end |
.method_missing(method_name, *args) ⇒ Object?
Handles dynamic method calls for variable access
Delegates to Vars.method_missing to support both getter and setter syntax.
73 74 75 |
# File 'documented/common/uservars.rb', line 73 def UserVars.method_missing(method_name, *args) Vars.method_missing(method_name, *args) end |
.respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Declares that method_missing can respond to valid Ruby method names
Delegates to Vars.respond_to_missing?.
85 86 87 |
# File 'documented/common/uservars.rb', line 85 def UserVars.respond_to_missing?(method_name, include_private = false) Vars.respond_to_missing?(method_name, include_private) end |