11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/hamstar.rb', line 11
def update_having(c, *match_path, &block)
if match_path.empty?
raise ArgumentError, "must have at least one matcher in path"
end
matcher = match_path[0]
case matcher
when KLEENE_STAR; match ->(k,v){true}, c, *match_path, &block
when Array, Hamster::Vector; match ->(k,v){key,value=matcher; value === v[key]}, c, *match_path, &block
when Proc; match matcher, c, *match_path, &block
else
if match_path.size == 1
new_value = block.call c.fetch(matcher,nil)
else
value = c.fetch matcher, Hamster::EmptyHash
new_value = update_having value, *match_path[1..-1], &block
end
c.put matcher, new_value
end
end
|