Skip to content

Commit

Permalink
Support [] and []= methods
Browse files Browse the repository at this point in the history
  • Loading branch information
greyblake committed Jul 11, 2016
1 parent 9ade38a commit db6bd39
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ crystal spec ./spec/kiwi/file_store_spec.cr

# Roadmap

* Support `#[]=`, `#[]` methods
* Write `Why?` section
* Cache use case
* Easy switch to a different store.
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ macro behaves_like_store(store_definition)
store.get("key2").should eq "value2"
store.get("key3").should eq "value3"

# []= and [] aliases
store["key1"] = "abc"
store["key1"].should eq "abc"

# clear
store.clear.should eq store
store.get("key1").should eq nil
Expand Down
8 changes: 8 additions & 0 deletions src/kiwi/store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ module Kiwi
abstract def set(key : String, val : String) : String
abstract def delete(key : String) : String|Nil
abstract def clear : Store

def []=(*args)
set(*args)
end

def [](*args)
get(*args)
end
end
end

0 comments on commit db6bd39

Please sign in to comment.