Project

General

Profile

Actions

Misc #17842

closed

Example incorrect in documentation for Hash#dig

Added by nickkelley (Nick Kelley) almost 3 years ago. Updated almost 3 years ago.


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) almost 3 years ago

Here is a pull request that fixes the comment: https://github.com/ruby/ruby/pull/4441

Actions #2

Updated by nickkelley (Nick Kelley) almost 3 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) almost 3 years ago

Thanks for the fix! I merged your pull request.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0