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 9CFD019C004F for ; Fri, 6 Nov 2015 12:47:50 +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 3BCB4B5D894 for ; Fri, 6 Nov 2015 13:16:53 +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 776AA18CC7B9 for ; Fri, 6 Nov 2015 13:16:53 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 8210B120518; Fri, 6 Nov 2015 13:16:51 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id 36C041204F0 for ; Fri, 6 Nov 2015 13:16:47 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=ul0YVgF7ASvntHfNBkQ+U8OmWAU=; b=INjfuTfYt7ct//xvQm RXhKIEGKP/4hCcv6fGjK1nctTptEjSk++qi0cWOC++nTw8puwMF13uiE9dcDbu6f cZKKHsIA4q4P7ivLz2eULc3ev/3oq5tywu4dhZfwoyXM259oaVgBpb++8UHvaIAK mYSCd8Of0LhWcfIKbartAjiVI= Received: by filter-135.sjc1.sendgrid.net with SMTP id filter-135.18029.563C29AD12 2015-11-06 04:16:45.600933671 +0000 UTC Received: from herokuapp.com (ec2-23-22-160-163.compute-1.amazonaws.com [23.22.160.163]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id Lx5AtcpTSUeUngSyL_cGwQ for ; Fri, 06 Nov 2015 04:16:45.504 +0000 (UTC) Date: Fri, 06 Nov 2015 04:16:45 +0000 From: shugo@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 46011 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11537 X-Redmine-Issue-Author: hsbt X-Redmine-Issue-Assignee: matz X-Redmine-Sender: shugo X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS4ikvgUn+6vwMOuX0/viWCofoacCxY8+h34pn 2iTVvDZlRnLZBMq3rMxWCi7nZtlBDKNbQ4COhdeII26edq9eCNMD0rUpdu8Xj9Cw5/dmHS37n8DGvd XBypJSzhp7/uqvw= X-ML-Name: ruby-core X-Mail-Count: 71370 Subject: [ruby-core:71370] [Ruby trunk - Feature #11537] [Open] 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" Issue #11537 has been updated by Shugo Maeda. Status changed from Closed to Open Yukihiro Matsumoto wrote: > I think about this for a while, and thinking of introducing `&.` instead of `.?`, because: It sounds nice because &. is more friendly to syntax highlighting of my favorite editor, but le me play devil's advocate here. > * `.?` is similar to `?.` in Swift and other languages, but is different anyway. This also applies to `->`, but `->` is accepted now, so it's not a strong reason. > * Since `?` is a valid suffix of method names in Ruby, we already see a lot of question marks in our programs. `&` also has other roles such as a binary operator and the prefix for block arguments. The current syntax allows `x.&y` as a valid expression, whose behavior is the same as `x & y`, so it may be confusing. ---------------------------------------- Feature #11537: Introduce "Safe navigation operator" https://bugs.ruby-lang.org/issues/11537#change-54739 * Author: Hiroshi SHIBATA * Status: Open * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- I sometimes write following code with rails application: ```ruby u = User.find(id) if u && u.profile && u.profile.thumbnails && u.profiles.thumbnails.large ... ``` or ```ruby # Use ActiveSupport if u.try!(:profile).try!(:thumbnails).try!(:large) ... ``` I hope to write shortly above code. Groovy has above operator named "Safe navigation operator" with "`?.`" syntax. Ruby can't use "`?.`" operator. Can we use "`.?`" syntax. like this: ```ruby u = User.find(id) u.?profile.?thumbnails.?large ``` Matz. How do you think about this? -- https://bugs.ruby-lang.org/