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
Implement Hash#path_to_key #1847
Conversation
@skateman This is the implementation I came up with. |
Where For recursive hash, |
@nobu Interesting comment.... About number two, I will add a test for this case and fix it. |
hash.c
Outdated
keys = rb_hash_keys(hash); | ||
prev_hsh = hash; | ||
|
||
for (int i = 0; i < RARRAY_LEN(keys); ++i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declaration in for
is not C89.
Why not |
I think it might make more sense, @nobu . I will check it out on how can I approach that and change it. |
I guess that you'd expect |
…t lead to the supplied key
Yes @nobu. Just fixed that and another recursive hash issue... |
I will have to slightly change the implementation of this, because hashes like hsh = {:x=>{:e=>1}, :y=>[1, 2, 3], :z=>{:a=>{:w=>100}}}
hsh.path_to_key(:w) will be expected to return |
|
|
What do you expect when a hash has multiple paths to the same key, e.g., |
The right expectation would be |
Hey @nobu. Can you re-check this? I have re-implemented using a recursive approach, but I don't know how much my recursion design might hurt some other parts. I've used some of the recursions over the hash as base. Cheers |
@rudy-on-rails Can you address this feature request to https://bugs.ruby-lang.org? We do not handle new feature on GitHub. |
Hey @hsbt , sure thing. I will write the rationale there. |
It seems to have a conflict now. Could you rebase this from master? |
Let me close this as it has not been updated for a while. Please reopen this after resolving conflicts. Thanks. |
This PR is a first attempt to contribute to MRI, done at the RubyHackChallenge at Cookpad office in Bristol. I apologize in advance for anything that might be missing here, in relation to how this should be approached.
It has been started with ko1/rubyhackchallenge#41. After the implementation, me and @skateman had a chart with @matz about how applicable would it be to have that code merged.
Matz suggested that a method like this, described afterwards in ko1/rubyhackchallenge#44, would have more applicability and just generally be more useful.