Module: SessionVars
- Defined in:
- documented/sessionvars.rb
Overview
Provides a way to manage session variables.
This module allows for dynamic access to session variables using a hash.
Constant Summary collapse
- @@svars =
Hash.new
Class Method Summary collapse
-
.[](name) ⇒ String?
Retrieves the value of a session variable by name.
-
.[]=(name, val) ⇒ void
Sets the value of a session variable by name.
-
.list ⇒ Hash
Returns a duplicate of the current session variables.
-
.method_missing(arg1, arg2 = '') ⇒ String?
Handles dynamic method calls for session variable access.
Class Method Details
.[](name) ⇒ String?
Retrieves the value of a session variable by name.
13 14 15 |
# File 'documented/sessionvars.rb', line 13 def self.[](name) @@svars[name] end |
.[]=(name, val) ⇒ void
This method returns an undefined value.
Sets the value of a session variable by name.
21 22 23 24 25 26 27 |
# File 'documented/sessionvars.rb', line 21 def self.[]=(name, val) if val.nil? @@svars.delete(name) else @@svars[name] = val end end |
.list ⇒ Hash
Returns a duplicate of the current session variables.
31 32 33 |
# File 'documented/sessionvars.rb', line 31 def self.list @@svars.dup end |
.method_missing(arg1, arg2 = '') ⇒ String?
Handles dynamic method calls for session variable access. This allows for setting and getting session variables using method names.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'documented/sessionvars.rb', line 40 def self.method_missing(arg1, arg2 = '') if arg1[-1, 1] == '=' if arg2.nil? @@svars.delete(arg1.to_s.chop) else @@svars[arg1.to_s.chop] = arg2 end else @@svars[arg1.to_s] end end |