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 7A87E19C0020 for ; Fri, 23 Oct 2015 05:52:46 +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 28331B5D85C for ; Fri, 23 Oct 2015 06:19:59 +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 25DB1952408 for ; Fri, 23 Oct 2015 06:19:58 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 0FFEF1204E2; Fri, 23 Oct 2015 06:19:57 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from mail-qg0-f44.google.com (mail-qg0-f44.google.com [209.85.192.44]) by neon.ruby-lang.org (Postfix) with ESMTPS id BD20F1204C7 for ; Fri, 23 Oct 2015 06:19:49 +0900 (JST) Received: by qgbb65 with SMTP id b65so68713345qgb.2 for ; Thu, 22 Oct 2015 14:19:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:content-type; bh=XBpZY16joRilkxAKv6i6pTtuBoZvCGaYWaq6/BGD+Gk=; b=RIoi41dd0Lg3ps8Upmy1HP1kr3M0ISOGhPe9KKKQx06fCJeMPhenfYqlemmScI8DUb C/jakMaH2+050DBVky/9CA+qucU4Ye+8lckyS8qFBaUu2emKhf3xNhCuDOCOa0Huk5Pg QOQjdtwV3TVhiZGx5V44dPh7AywIUbAXTQfkvfqvMVwfJo/jBuEpMRsDTg6M5EHB86wj gzlYjdmbgmgiDSTyJYcQxqdagWltsjyqInW5uqZ8ZigsCnwPkq4aHyPqEPjUFuOcukVO peh+AkUwI9XnE/M+nZqOq4dPEyxxrByBzJLIEsPkxXxwFgOMKuJazJOg0o9K632m0fFM ZJrA== MIME-Version: 1.0 X-Received: by 10.140.96.135 with SMTP id k7mr21820586qge.34.1445548787511; Thu, 22 Oct 2015 14:19:47 -0700 (PDT) Received: by 10.55.203.141 with HTTP; Thu, 22 Oct 2015 14:19:47 -0700 (PDT) Received: by 10.55.203.141 with HTTP; Thu, 22 Oct 2015 14:19:47 -0700 (PDT) In-Reply-To: References: Date: Fri, 23 Oct 2015 07:19:47 +1000 X-Google-Sender-Auth: I5NZbe3f5tqiOb-5A6QewXUB2GM Message-ID: From: Matthew Kerwin To: Ruby developers Content-Type: multipart/alternative; boundary=001a113a3e0afc39130522b80d3b X-ML-Name: ruby-core X-Mail-Count: 71166 Subject: [ruby-core:71166] Re: [Ruby trunk - Feature #11537] Introduce "Safe navigation operator" 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" --001a113a3e0afc39130522b80d3b Content-Type: text/plain; charset=UTF-8 On 23/10/2015 2:46 AM, wrote: > > Issue #11537 has been updated by Jeremy Evans. > > > Tom Reznick wrote: > > Hi, > > > > I think we may have found some unexpected behavior with the `.?` operator. > > > > If I call the following: > > > > s = Struct.new(:x) > > o = s.new() > > o.x #=> nil > > o.x.nil? #=> true > > o.x.?nil? #=> nil > > o.x.kind_of?(NilClass) #=> true > > o.x.?kind_of?(NilClass) #=> nil > > o.x.methods.include?(:nil?) #=> true > > > > > > While it's arguably a bit peculiar to try to check that `nil` is `nil`, in a `nil`-safe way, `.?kind_of?(NilClass)` could reasonably return `true`. > > I think it's completely expected that `nil.?kind_of?(NilClass)` returns `nil` and not `true`. The whole point of `.?` is to return `nil` without calling the method if the receiver is `nil`. I'm not sure if `.?` is a good idea syntax-wise, but if you are going to have it, it shouldn't have special cases for specific methods. > I agree, or put another way: if you're testing for nil in two ways, .? has higher priority. That makes it a programmer issue, not a ruby one. --001a113a3e0afc39130522b80d3b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On 23/10/2015 2:46 AM, <merch-redmine@jeremyevans.net> wrote:
>
> Issue #11537 has been updated by Jeremy Evans.
>
>
> Tom Reznick wrote:
> > Hi,
> >
> > I think we may have found some unexpected behavior with the `.?` = operator.
> >
> > If I call the following:
> >
> >=C2=A0 =C2=A0 =C2=A0s =3D Struct.new(:x)
> >=C2=A0 =C2=A0 =C2=A0o =3D s.new()
> >=C2=A0 =C2=A0 =C2=A0o.x #=3D> nil
> >=C2=A0 =C2=A0 =C2=A0o.x.nil? #=3D> true
> >=C2=A0 =C2=A0 =C2=A0o.x.?nil? #=3D> nil
> >=C2=A0 =C2=A0 =C2=A0o.x.kind_of?(NilClass) #=3D> true
> >=C2=A0 =C2=A0 =C2=A0o.x.?kind_of?(NilClass) #=3D> nil
> >=C2=A0 =C2=A0 =C2=A0o.x.methods.include?(:nil?) #=3D> true
> >
> >
> > While it's arguably a bit peculiar to try to check that `nil`= is `nil`, in a `nil`-safe way, `.?kind_of?(NilClass)` could reasonably ret= urn `true`.
>
> I think it's completely expected that `nil.?kind_of?(NilClass)` re= turns `nil` and not `true`.=C2=A0 The whole point of `.?` is to return `nil= ` without calling the method if the receiver is `nil`.=C2=A0 I'm not su= re if `.?` is a good idea syntax-wise, but if you are going to have it, it = shouldn't have special cases for specific methods.
>

I agree, or put another way: if you're testing for nil i= n two ways, .? has higher priority. That makes it a programmer issue, not a= ruby one.

--001a113a3e0afc39130522b80d3b--