-
-
Notifications
You must be signed in to change notification settings - Fork 120
Proposition: the dig did not work on my machine #78
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
Conversation
The dig solution did not work on my machine, but I am not sure why (quite new with ruby and rails). the solution with brackets wroks, so maybe we can change that, But any explanation is really welcomed 😄
If you agreed with the change, we should also change the example that use dig. I think there is 4 or 5 example that use this sample (for the factorisation) |
oooohhh ok find the issue...
|
I think Here an example to reproduce error: 2.6.5 :001 > require 'json'
2.6.5 :002 > data = JSON.parse '{ "a": { "b": { "c" : 1 } } }'
=> {"a"=>{"b"=>{"c"=>1}}}
2.6.5 :003 > data.dig :a, :b, :c
=> nil using 2.6.5 :004 > data = JSON.parse '{ "a": { "b": { "c" : 1 } } }', symbolize_names: true
=> {:a=>{:b=>{:c=>1}}}
2.6.5 :005 > data.dig :a, :b, :c
=> 1 We should avoid using array because this may produce 2.6.5 :006 > data[:x][:y][:z]
Traceback (most recent call last):
7: from /home/alexandre/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `<main>'
6: from /home/alexandre/.rvm/gems/ruby-2.6.5/bin/ruby_executable_hooks:24:in `eval'
5: from /home/alexandre/.rvm/rubies/ruby-2.6.5/bin/irb:23:in `<main>'
4: from /home/alexandre/.rvm/rubies/ruby-2.6.5/bin/irb:23:in `load'
3: from /home/alexandre/.rvm/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
2: from (irb):06
1: from (irb):06:in `rescue in irb_binding'
NoMethodError (undefined method `[]' for nil:NilClass) Can you update your MR to use your previous proposition ? |
yep sure I will do that. Thanks for the explanation ! |
Co-authored-by: Alexandre Rousseau <contact@rousseau-alexandre.fr>
thank you for your contributions ❤️ |
The dig solution did not work on my machine, but I am not sure why (quite new with ruby and rails).
the solution with brackets wroks, so maybe we can change that, But any explanation is really welcomed 😄