Skip to content

Commit e816668

Browse files
committed
Add Base.get(instance::Instance, key::AbstractString, default::Any)
1 parent 0a22317 commit e816668

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/instance.jl

+13-8
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,26 @@ function save(instance::Instance, content::Dict)
4444
end
4545

4646
function set!(instance::Instance, key::AbstractString, value::Any)
47-
toml = load(instance)
48-
toml[key] = value
49-
save(instance, toml)
47+
dict = load(instance)
48+
dict[key] = value
49+
save(instance, dict)
5050
return nothing
5151
end
5252

5353
function Base.get(instance::Instance, key::AbstractString)
54-
toml = load(instance)
55-
return toml[key]
54+
dict = load(instance)
55+
return dict[key]
56+
end
57+
58+
function Base.get(instance::Instance, key::AbstractString, default::Any)
59+
dict = load(instance)
60+
return get(dict, key, default)
5661
end
5762

5863
function remove!(instance::Instance, key::AbstractString)
59-
toml = load(instance)
60-
delete!(toml, key)
61-
save(instance, toml)
64+
dict = load(instance)
65+
delete!(dict, key)
66+
save(instance, dict)
6267
return nothing
6368
end
6469

0 commit comments

Comments
 (0)