File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 1
1
* Add ` session#fetch ` method
2
2
3
- fetch behaves like [ Hash#fetch] ( http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-fetch ) .
3
+ fetch behaves similarly to [ Hash#fetch] ( http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-fetch ) ,
4
+ with the exception that the returned value is always saved into the session.
5
+
4
6
It returns a value from the hash for the given key.
5
7
If the key can’t be found, there are several options:
6
8
Original file line number Diff line number Diff line change @@ -63,11 +63,15 @@ def test_clear
63
63
64
64
def test_fetch
65
65
session = Session . create ( store , { } , { } )
66
- session [ 'one' ] = '1'
67
66
67
+ session [ 'one' ] = '1'
68
68
assert_equal '1' , session . fetch ( :one )
69
+
69
70
assert_equal '2' , session . fetch ( :two , '2' )
71
+ assert_equal '2' , session . fetch ( :two )
72
+
70
73
assert_equal 'three' , session . fetch ( :three ) { |el | el . to_s }
74
+ assert_equal 'three' , session . fetch ( :three )
71
75
72
76
assert_raise KeyError do
73
77
session . fetch ( :four )
You can’t perform that action at this time.
0 commit comments