Actions
Misc #17842
closedExample incorrect in documentation for Hash#dig
Status:
Closed
Assignee:
Description
In the current examples for Hash#dig, we have:
h = {foo: {bar: {baz: 2}}}
h.dig(:foo) # => {:bar=>{:baz=>2}}
h.dig(:foo, :bar) # => {:bar=>{:baz=>2}} <-- incorrect return value
This should be:
h = {foo: {bar: {baz: 2}}}
h.dig(:foo) # => {:bar=>{:baz=>2}}
h.dig(:foo, :bar) # => {:baz=>2}
I have a pull request incoming to fix this on GitHub, but I can create a patch and post it here if that is better.
Documentation link for reference: https://ruby-doc.org/core-3.0.1/Hash.html#method-i-dig
Updated by nickkelley (Nick Kelley) about 4 years ago
Here is a pull request that fixes the comment: https://github.com/ruby/ruby/pull/4441
Updated by nickkelley (Nick Kelley) about 4 years ago
- Status changed from Open to Closed
Applied in changeset git|a9824a3113ee5342e7ac90387de9f3b9d5ec9e0a.
Correct documentation example on Hash#dig
Fixes [Misc #17842]. The current documentation suggests that:
{foo: {bar: {baz: 2}}}.dig(:foo, :bar) # => {:bar=>{:baz=>2}}
when it should be:
{foo: {bar: {baz: 2}}}.dig(:foo, :bar) # => {:baz=>2}
Updated by jeremyevans0 (Jeremy Evans) about 4 years ago
Thanks for the fix! I merged your pull request.
Actions
Like0
Like0Like0Like0