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 7805119C0036 for ; Wed, 4 Nov 2015 08:38:38 +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 91500B5D959 for ; Wed, 4 Nov 2015 09:07:24 +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 76556952439 for ; Wed, 4 Nov 2015 09:07:24 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 0F963120516; Wed, 4 Nov 2015 09:07:23 +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 C7C921204C6 for ; Wed, 4 Nov 2015 09:07:19 +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=sHATEMyxz+T+EMHXll8aiFzUSJY=; b=PZo9NmJGYVYGhXKQeE kgaaUk4Wj1cc6OFkw313mLbmSAjsSvcgbpeZoAMky27fofksMH45RmVMagA3rGwU vzpazicOZSRsvW75mEE/HrbHcw1WVPy5e6H2hx35jfzyTN6OE22896tnOih6+TY4 8EHYWeumwXhqg6VVrarg9p8W8= Received: by filter0609p1mdw1.sendgrid.net with SMTP id filter0609p1mdw1.7215.56394C2D4C 2015-11-04 00:07:09.623341594 +0000 UTC Received: from herokuapp.com (ec2-54-166-23-0.compute-1.amazonaws.com [54.166.23.0]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id PkJg3SI4SdaQmzTl9G5Ylg for ; Wed, 04 Nov 2015 00:07:09.533 +0000 (UTC) Date: Wed, 04 Nov 2015 00:07:09 +0000 From: transfire@gmail.com 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: 45964 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11537 X-Redmine-Issue-Author: hsbt X-Redmine-Issue-Assignee: matz X-Redmine-Sender: trans 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS6uCIG4YFpxmPiT0mygDeieUsQF06mYi0DZg9 071zIqwo+IA+R4XkZpyhd4WkxkAO04lp6IDi8tPyLMwNLQNgV6WngQGguQp4oSxFK5EPMB2mhqRxVZ UKNEShy1clhHU5id3svI3F6uYJSaWzcW4d++ X-ML-Name: ruby-core X-Mail-Count: 71324 Subject: [ruby-core:71324] [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" Issue #11537 has been updated by Thomas Sawyer. Philip Claren wrote: > Thomas Sawyer wrote: > > In this way is more an extension of the ternary operator -- the initial dot on the method signals the difference. This should also allow: > > > > u ? .profile ? .thumbnails ? .large : default > > Although I agree that .? is not that intuitive to read, the extended ternary operator would have a problem: boolean false passes for the safe navigator (because it's a valid value) but not for the ternary operator. Is allowing false necessary/useful? On the other hand, if it is, then might a nil-only ternary operator be useful too (regardless of this issue)? ---------------------------------------- Feature #11537: Introduce "Safe navigation operator" https://bugs.ruby-lang.org/issues/11537#change-54699 * Author: Hiroshi SHIBATA * Status: Closed * 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/