Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bringing this up to Crystal 1.9.2 compatibility: #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixing small bug in the new #fetch method
akitaonrails committed Aug 31, 2023
commit 96c2b0337eeae79e3f9275459f30d4d60335b600
3 changes: 2 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -28,10 +28,11 @@ macro behaves_like_store(store_definition)
store["key1"].should eq "abc"

# fetch
store.fetch("key9") do
value = store.fetch("key9") do
"value9"
end
store["key9"].should eq "value9"
value.should eq "value9"

# clear
store.clear.should eq store
8 changes: 4 additions & 4 deletions src/kiwi/store.cr
Original file line number Diff line number Diff line change
@@ -8,11 +8,11 @@ module Kiwi
abstract def clear : Store

def fetch(key : String, &) : String?
get(key).tap do |value|
if !value && (value = yield)
set(key, value)
end
value = get(key)
if !value && (value = yield)
set(key, value)
end
value
end

def []=(*args)