From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 6FEAC19C04A9 for ; Mon, 30 Nov 2015 07:53:54 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 201ACB5D853 for ; Mon, 30 Nov 2015 08:25:12 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id 53E6718CC7D0 for ; Mon, 30 Nov 2015 08:25:12 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 9E589120477; Mon, 30 Nov 2015 08:25:09 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from mail-yk0-f180.google.com (mail-yk0-f180.google.com [209.85.160.180]) by neon.ruby-lang.org (Postfix) with ESMTPS id 8EDF0120468 for ; Mon, 30 Nov 2015 08:25:05 +0900 (JST) Received: by ykdv3 with SMTP id v3so165586731ykd.0 for ; Sun, 29 Nov 2015 15:25:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=FYKpWpBPAMAZZdAfdPcFalBCcR0z5pY4Sd6HCFeKShk=; b=UjpLZdZte+w3vZcQ5U0NYKnwoRHiGNxSrokPFetVr98h/xh2qv9kQ+/vJDvGD13jaH bG1sV95s49A34QZ7x6R3dydjIfsB6/jWTTPvSOXCQ3ZbuD2I24SL8Icvw15BKVyZzPc2 Ddvl2E7MIyAqSkxCeO/d5MeT2HfXNAPiuRWv7C+mgMc6eS2V9h8eqj1XEyWDPigN6NeS ka2vW/+ZhFvuMfpAeBPEDI8a7v9RIAMZufdktToWw0wCZ8MPgcCGnF7zZMuVK7meh2MD 8AS762WNhxMcTYeNgjSHIV6BmULMkfwjJQrpljQKmHI3qk2T93nh2aSnSTfUyDIYc1P+ kRVw== X-Received: by 10.129.129.130 with SMTP id r124mr972824ywf.242.1448839502694; Sun, 29 Nov 2015 15:25:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.207.203 with HTTP; Sun, 29 Nov 2015 15:24:33 -0800 (PST) From: Colin Kelley Date: Sun, 29 Nov 2015 15:24:33 -0800 Message-ID: To: ruby-core@ruby-lang.org Content-Type: multipart/alternative; boundary=94eb2c055098e50f230525b63bf3 X-ML-Name: ruby-core X-Mail-Count: 71738 Subject: [ruby-core:71738] behavior of Array#dig when passed a non-numeric index? X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" --94eb2c055098e50f230525b63bf3 Content-Type: text/plain; charset=UTF-8 Hello, I am working on this gem to provide backward-compatibility of the new `dig` method in `Hash` and `Array`. https://rubygems.org/gems/ruby_dig (See the accompanying blog post for more info. http://development.invoca.com/ruby_dig-gem-adds-hash-dig-and-array-dig-from-ruby-2-3-to-earlier-versions/ ) But I can't tell from the documentation or tests in the original commit https://github.com/ruby/ruby/commit/29862685c0acf3a40c6b1f9e8780cbbd86cba658 what is supposed to happen if Array#dig is passed a non-numeric index. For example: ['zero', 'one', 'two'].dig(:first) It seems like the C code is just calling the `[]` operator, in which case it would raise this exception: TypeError: no implicit conversion of Symbol into Integer But it definitely seems like the spirit of `dig` that `nil` should be returned if the expected structure isn't there. I believe the most typical use case for `dig` is to dig through a JSON hash and either find the result we expected, or get `nil`. Wouldn't it defeat the purpose of `dig` if we had to wrap it in a `rescue`? Can we clarify the desired behavior, then update the documentation and tests to reflect that? -Colin --94eb2c055098e50f230525b63bf3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello,

I am working on this gem to prov= ide backward-compatibility of the new `dig` method in `Hash` and `Array`.= =C2=A0


=
<= div>
But I can't tell from the documentation or tests in = the original commit





--94eb2c055098e50f230525b63bf3--