diff --git a/lib/jsonpath/enumerable.rb b/lib/jsonpath/enumerable.rb index 29660ab..a29e1e1 100644 --- a/lib/jsonpath/enumerable.rb +++ b/lib/jsonpath/enumerable.rb @@ -144,7 +144,7 @@ def yield_value(blk, context, key) if key context[key] = blk.call(context[key]) else - context.replace(blk.call(context[key])) + context.replace(blk.call(context)) end end end diff --git a/test/test_jsonpath.rb b/test/test_jsonpath.rb index 80fa0bb..afc2016 100644 --- a/test/test_jsonpath.rb +++ b/test/test_jsonpath.rb @@ -260,6 +260,10 @@ def test_join assert_equal JsonPath.new('$.store.book..author').on(@object), JsonPath.new('$.store').join('book..author').on(@object) end + def test_gsub_with_nokey + assert_equal @object2, JsonPath.for(@object).gsub('$..*[?(@.category=="fiction")]') { |v| v }.to_hash + end + def test_gsub @object2['store']['bicycle']['price'] += 10 @object2['store']['book'][0]['price'] += 10