aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorDamien Mathieu <42@dmathieu.com>2013-10-29 17:00:45 +0100
committerDamien Mathieu <42@dmathieu.com>2013-10-29 20:37:15 +0100
commit84c9f4164bbd5f3d2697949bdd2cdbd15ce6091e (patch)
treeaa9262a5a74a9bbfea4bd2bffe0cbd411b95873c /actionpack/lib
parentdf2226ea16922fd4e2ea72b8ee372a4cb5621114 (diff)
downloadrails-84c9f4164bbd5f3d2697949bdd2cdbd15ce6091e.tar.gz
rails-84c9f4164bbd5f3d2697949bdd2cdbd15ce6091e.tar.bz2
rails-84c9f4164bbd5f3d2697949bdd2cdbd15ce6091e.zip
add the fetch method to sessions
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/request/session.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb
index 7bc812fd22..6d911a75f1 100644
--- a/actionpack/lib/action_dispatch/request/session.rb
+++ b/actionpack/lib/action_dispatch/request/session.rb
@@ -127,6 +127,18 @@ module ActionDispatch
@delegate.delete key.to_s
end
+ def fetch(key, default=nil)
+ if self.key?(key)
+ self[key]
+ elsif default
+ self[key] = default
+ elsif block_given?
+ self[key] = yield(key)
+ else
+ raise KeyError
+ end
+ end
+
def inspect
if loaded?
super