Class: Sinatra::Flash::FlashHash
- Inherits:
-
Object
- Object
- Sinatra::Flash::FlashHash
- Defined in:
- lib/sinatra-flash.rb
Overview
Implements bracket accessors for storing and retrieving flash entries.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Remove an entry from the session and return its value.
-
#[]=(key, val) ⇒ Object
Store the entry in the session, updating the instance cache as well.
-
#initialize(session) ⇒ FlashHash
constructor
A new instance of FlashHash.
-
#inspect ⇒ Object
Hide the underlying :__FLASH__ session key and only expose values stored in the flash.
Constructor Details
#initialize(session) ⇒ FlashHash
Returns a new instance of FlashHash.
5 6 7 8 |
# File 'lib/sinatra-flash.rb', line 5 def initialize(session) @session = session @session[:__FLASH__] ||= {} end |
Instance Method Details
#[](key) ⇒ Object
Remove an entry from the session and return its value. Cache result in the instance cache.
12 13 14 |
# File 'lib/sinatra-flash.rb', line 12 def [](key) cache[key] ||= values.delete(key) end |
#[]=(key, val) ⇒ Object
Store the entry in the session, updating the instance cache as well.
17 18 19 |
# File 'lib/sinatra-flash.rb', line 17 def []=(key,val) cache[key] = values[key] = val end |
#inspect ⇒ Object
Hide the underlying :__FLASH__ session key and only expose values stored in the flash.
23 24 25 |
# File 'lib/sinatra-flash.rb', line 23 def inspect '#<FlashHash @values=%s>' % [values.inspect] end |