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 C860119E0032 for ; Mon, 7 Dec 2015 16:10:08 +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 B0D31B5D890 for ; Mon, 7 Dec 2015 16:41:45 +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 29E2918CC7D1 for ; Mon, 7 Dec 2015 16:41:46 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B81701204CA; Mon, 7 Dec 2015 16:41:44 +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 681BD1204B9 for ; Mon, 7 Dec 2015 16:41:41 +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=ROxmO08J7SFdNDDbZLu74rFioF4=; b=WIPtnc64zqmQRQj3et B2VKSp5NJUAayLvViBHM0Da8ze6pWJT0YD4XWtVMhoW3hmxEMo8Mf+OI4HdC+8/S +jGRRIU9RY1bwIhoinaV+YOlJUT9f18sRV/wt36b0FD6aE7LfcLgpdxFraq0aEft x20fkkaLSsxqkV5RsFJ5VRjGA= Received: by filter0427p1mdw1.sendgrid.net with SMTP id filter0427p1mdw1.12034.5665383023 2015-12-07 07:41:36.462242024 +0000 UTC Received: from herokuapp.com (ec2-54-197-84-115.compute-1.amazonaws.com [54.197.84.115]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id XbhFzyuUSNKB-fVxRLDb8A for ; Mon, 07 Dec 2015 07:41:36.381 +0000 (UTC) Date: Mon, 07 Dec 2015 07:41:36 +0000 From: matz@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: 46585 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11737 X-Redmine-Issue-Author: danielpclark X-Redmine-Sender: matz 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS6ejU46/wah8cHOYT/iUflJCLO1pgcYqJrj5k qufbm6hy3m4BQ/1DIGZ8cQkBfun6flFmOa/OdmvyDMGVFtn8C48dmfLuhI9ozpmt8Nc11d+xmOFd7e zjmo1hEkPZoU8YHweFQ+1BOQifoV6rGutspt X-ML-Name: ruby-core X-Mail-Count: 71888 Subject: [ruby-core:71888] [Ruby trunk - Feature #11737] [Rejected] Pass in expression to then block in `case expression` 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 #11737 has been updated by Yukihiro Matsumoto. Status changed from Open to Rejected It's not worth adding special expression or variable for retrieving the when value. Just use assignment. Matz. ---------------------------------------- Feature #11737: Pass in expression to then block in `case expression` https://bugs.ruby-lang.org/issues/11737#change-55294 * Author: Daniel P. Clark * Status: Rejected * Priority: Normal * Assignee: ---------------------------------------- Ruby's `case ` scenario allows the expression to be tested in the `when` test with `:===`, but in the then block the expression is not accessible. Only if the expression has been assigned to a variable beforehand can it be checked. ~~~ruby case 4 when ->i{ puts :when; true} ->i{ puts i} else :foo end # when # => # case 4 when ->i{ puts :when; true} puts _ else :foo end # when # # # => nil case 4 when 4 then _ end # => nil case 4 when 4 then ->i{puts i} end # => # ~~~ If some one wanted to give an expression after case that wasn't assigned to a variable then there is no access to it in the then block. I suggest assigning the expression to the `_` variable during a case/when/then scenario. Here's a rather contrived example use case. ~~~ruby case Enumerator.new do |y| y << 1; y << 2; y << 3; end when ->e{ 2.times e.next; true} then _.peek end == 3 ~~~ -- https://bugs.ruby-lang.org/