A Flash is a special hash object that lives in the session. The values stored in the Flash are typically maintained for the duration of one request. After the request is over, the Hash is cleared.

You may want to use the Flash to pass error messages or other short lived objects.

Use capitalized keys to denote system variables. Reserve lower case keys for user application variables.

Contents
Methods
Public Class methods
new()
    # File lib/raw/context/flash.rb, line 22
22:       def initialize
23:         super
24:         @dirty = {}
25:       end
Public Instance methods
[]=(key, val)
    # File lib/raw/context/flash.rb, line 27
27:       def []=(key, val)
28:         super
29:         keep(key)
30:       end
discard(key = nil)

Discard the specific key or the whole Flash.

    # File lib/raw/context/flash.rb, line 40
40:       def discard(key = nil)
41:         set_dirty(key)
42:       end
keep(key = nil)

Keep the specific key or the whole Flash.

    # File lib/raw/context/flash.rb, line 34
34:       def keep(key = nil)
35:         set_dirty(key, false)
36:       end
Public Instance methods
concat(key, arr)

Another helper, concats a whole array to the given flash key.

     # File lib/raw/context/flash.rb, line 98
 98:       def concat(key, arr)
 99:         for val in arr.to_a
100:           push key, val
101:         end
102:       end
join(key, sep = ", ")

Join helper

     # File lib/raw/context/flash.rb, line 106
106:       def join(key, sep = ", ")
107:         value = self[key]
108:         
109:         if value.is_a? Array
110:           return value.join(sep)
111:         else
112:           return value
113:         end
114:       end
pop(key)

Pop a value from an array flash variable.

    # File lib/raw/context/flash.rb, line 84
84:       def pop(key)
85:         if arr = self[key]
86:           if arr.is_a? Array
87:             return arr.pop
88:           else
89:             return arr
90:           end
91:         end
92:         return nil
93:       end
push(key, *values)

Push a value in an array flash variable.

Example

flash.push :ERRORS, ‘This is the first error’ flash.push :ERRORS, ‘This is the second error’

flash[:ERRORS] # => []

    # File lib/raw/context/flash.rb, line 71
71:       def push(key, *values)
72:         val = self[key]
73:         val ||= []
74:         if values.size == 1
75:           val << values[0]
76:         else
77:           val << values
78:         end
79:         self[key] = val
80:       end