Skip to content

Commit eb68a92

Browse files
committed
Use compact
1 parent 0bf2705 commit eb68a92

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/kredis/types/hash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def []=(key, value)
1818
end
1919

2020
def update(**entries)
21-
hset entries.transform_values { |val| type_to_string(val, typed) } if entries.flatten.any?
21+
hset entries.transform_values { |val| type_to_string(val, typed) }.compact if entries.flatten.any?
2222
end
2323

2424
def values_at(*keys)

test/types/hash_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ class HashTest < ActiveSupport::TestCase
125125
assert_equal({ "space_invaders" => 100, "pong" => 42 }, @hash.to_h)
126126
end
127127

128-
test "does not support nil values" do
129-
assert_raises do
130-
@hash.update("key" => nil)
131-
end
128+
test "handles nil values gracefully" do
129+
@hash.update("key" => nil, "key2" => "value2")
130+
assert_nil @hash["key"]
131+
assert_equal "value2", @hash["key2"]
132132
end
133133
end

0 commit comments

Comments
 (0)