File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ def each_pair # :yields: [key, value]
158
158
#
159
159
# Returns +self+.
160
160
def each_value # :yields: value
161
- super { |v | yield YAML . load ( v ) }
161
+ super { |v | yield YAML . respond_to? ( :safe_load ) ? YAML . safe_load ( v ) : YAML . load ( v ) }
162
162
self
163
163
end
164
164
@@ -167,7 +167,7 @@ def each_value # :yields: value
167
167
#
168
168
# Returns an array of values from the database.
169
169
def values
170
- super . collect { |v | YAML . load ( v ) }
170
+ super . collect { |v | YAML . respond_to? ( :safe_load ) ? YAML . safe_load ( v ) : YAML . load ( v ) }
171
171
end
172
172
173
173
# :call-seq:
@@ -213,7 +213,9 @@ def replace( hsh )
213
213
# The order in which values are removed/returned is not guaranteed.
214
214
def shift
215
215
a = super
216
- a [ 1 ] = YAML . load ( a [ 1 ] ) if a
216
+ if a
217
+ a [ 1 ] = YAML . respond_to? ( :safe_load ) ? YAML . safe_load ( a [ 1 ] ) : YAML . load ( a [ 1 ] )
218
+ end
217
219
a
218
220
end
219
221
Original file line number Diff line number Diff line change @@ -22,4 +22,25 @@ def test_delete
22
22
assert_equal "value" , @dbm . delete ( "key" )
23
23
assert_nil @dbm [ "key" ]
24
24
end
25
+
26
+ def test_each_value
27
+ @dbm [ "key1" ] = "value1"
28
+ @dbm [ "key2" ] = "value2"
29
+ @dbm . each_value do |value |
30
+ assert_match ( /value[12]/ , value )
31
+ end
32
+ end
33
+
34
+ def test_values
35
+ @dbm [ "key1" ] = "value1"
36
+ @dbm [ "key2" ] = "value2"
37
+ @dbm . values . each do |value |
38
+ assert_match ( /value[12]/ , value )
39
+ end
40
+ end
41
+
42
+ def test_shift
43
+ @dbm [ "key" ] = "value"
44
+ assert_equal [ "key" , "value" ] , @dbm . shift
45
+ end
25
46
end
You can’t perform that action at this time.
0 commit comments