Module: Lich::Common::UserVars

Defined in:
lib/common/uservars.rb

Class Method Summary collapse

Class Method Details

.add(var_name, value, _t = nil) ⇒ String

Note:

This assumes the existing value is a comma-separated string.

Adds a value to a user variable, appending it to the existing value.

Examples:

UserVars.add("var1", "new_value")
# => "existing_value, new_value"

Parameters:

  • var_name (String)

    the name of the variable to add to.

  • value (Object)

    the value to append to the variable.

  • _t (nil) (defaults to: nil)

    an optional parameter (not used).

Returns:

  • (String)

    the updated value of the variable.



61
62
63
# File 'lib/common/uservars.rb', line 61

def UserVars.add(var_name, value, _t = nil)
  Vars[var_name] = Vars[var_name].split(', ').push(value).join(', ')
end

.change(var_name, value, _t = nil) ⇒ Object

Note:

This will overwrite the existing value of the variable.

Changes the value of a user variable.

Examples:

UserVars.change("var1", "new_value")
# => "new_value"

Parameters:

  • var_name (String)

    the name of the variable to change.

  • value (Object)

    the new value to assign to the variable.

  • _t (nil) (defaults to: nil)

    an optional parameter (not used).

Returns:

  • (Object)

    the new value of the variable.



45
46
47
# File 'lib/common/uservars.rb', line 45

def UserVars.change(var_name, value, _t = nil)
  Vars[var_name] = value
end

.delete(var_name, _t = nil) ⇒ nil

Deletes a user variable by setting it to nil.

Examples:

UserVars.delete("var1")
# => nil

Parameters:

  • var_name (String)

    the name of the variable to delete.

  • _t (nil) (defaults to: nil)

    an optional parameter (not used).

Returns:

  • (nil)

    always returns nil.



74
75
76
# File 'lib/common/uservars.rb', line 74

def UserVars.delete(var_name, _t = nil)
  Vars[var_name] = nil
end

.listArray

Lists all user variables.

Examples:

UserVars.list
# => ["var1", "var2", "var3"]

Returns:

  • (Array)

    an array of user variables.



14
15
16
# File 'lib/common/uservars.rb', line 14

def UserVars.list
  Vars.list
end

.list_charArray

Lists character-specific user variables.

Examples:

UserVars.list_char
# => ["char_var1", "char_var2"]

Returns:

  • (Array)

    an array of character-specific user variables.



96
97
98
# File 'lib/common/uservars.rb', line 96

def UserVars.list_char
  Vars.list
end

.list_globalArray

Lists all global user variables.

Examples:

UserVars.list_global
# => []

Returns:

  • (Array)

    an empty array, as global variables are not implemented.



85
86
87
# File 'lib/common/uservars.rb', line 85

def UserVars.list_global
  Array.new
end

.method_missing(arg1, arg2 = '') ⇒ Object

Handles missing methods for user variables.

Examples:

UserVars.some_missing_method
# => raises NoMethodError

Parameters:

  • arg1 (Symbol)

    the name of the method being called.

  • arg2 (String) (defaults to: '')

    an optional argument for the method.

Returns:

  • (Object)

    the result of the Vars method call.

Raises:

  • (NoMethodError)

    if the method does not exist in Vars.



29
30
31
# File 'lib/common/uservars.rb', line 29

def UserVars.method_missing(arg1, arg2 = '')
  Vars.method_missing(arg1, arg2)
end