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

This gem is not working for array of hashes. Does this work? #5

Open
rkhapre opened this issue Jul 31, 2020 · 2 comments
Open

This gem is not working for array of hashes. Does this work? #5

rkhapre opened this issue Jul 31, 2020 · 2 comments

Comments

@rkhapre
Copy link

rkhapre commented Jul 31, 2020

Hi

I liked this gem, but it is not working for array of hashes. Or i am not sure if i am missing something.

require 'vine'
require 'json'

json = '{
   "name":"John",
   "address":{
      "street":"street 1",
      "country":"country1"
   },
   "phone_numbers":[
      {
         "type":"mobile",
         "number":"234234"
      },
      {
         "type":"fixed",
         "number":"2342323423"
      }
   ]
}'

h = JSON.parse(json)
{"name"=>"John", "address"=>{"street"=>"street 1", "country"=>"country1"}, "phone_numbers"=>[{"type"=>"mobile", "number"=>"234234"}, {"type"=>"fixed", "number"=>"2342323423"}]}
a = h.access("phone_numbers.0.type")
mobile
b = h.set("phone_numbers.0.type", "tablet")
{"name"=>"John", "address"=>{"street"=>"street 1", "country"=>"country1"}, "phone_numbers"=>{0=>{:type=>"tablet"}}}

expected result is
{"name"=>"John", "address"=>{"street"=>"street 1", "country"=>"country1"}, "phone_numbers"=>[{"type"=>"tablet", "number"=>"234234"}, {"type"=>"fixed", "number"=>"2342323423"}]}

It is not working for array, or i am missing something. As documentation does not have any example for this
Thanks

@rkhapre
Copy link
Author

rkhapre commented Aug 1, 2020

@chengguangnan , is this set method with an array is part of the solution?

chengguangnan added a commit that referenced this issue Sep 3, 2020
increased the version number
@chengguangnan
Copy link
Owner

Hi @rkhapre ,

Sorry, just got your message. It should be fixed now. If you are using a Gemfile, try the latest version on github:

gem 'vine', github: 'chengguangnan/vine'

The commit is: 572d67d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants