Module: SessionVars
- Defined in:
- lib/sessionvars.rb
Overview
A module to manage session variables that are not persisted in a database.
Constant Summary collapse
- @@svars =
Hash.new
Class Method Summary collapse
-
.[](name) ⇒ Object?
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 = '') ⇒ Object?
Handles dynamic method calls for setting and getting session variables.
Class Method Details
.[](name) ⇒ Object?
Retrieves the value of a session variable by name.
15 16 17 |
# File 'lib/sessionvars.rb', line 15 def SessionVars.[](name) @@svars[name] end |
.[]=(name, val) ⇒ void
This method returns an undefined value.
Sets the value of a session variable by name.
26 27 28 29 30 31 32 |
# File 'lib/sessionvars.rb', line 26 def SessionVars.[]=(name, val) if val.nil? @@svars.delete(name) else @@svars[name] = val end end |
.list ⇒ Hash
Returns a duplicate of the current session variables.
39 40 41 |
# File 'lib/sessionvars.rb', line 39 def SessionVars.list @@svars.dup end |
.method_missing(arg1, arg2 = '') ⇒ Object?
Note:
This method allows for dynamic access to session variables using method names.
Handles dynamic method calls for setting and getting session variables.
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sessionvars.rb', line 52 def SessionVars.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 |