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 509E919C022B for ; Thu, 26 Nov 2015 03:25:56 +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 BEBB6B5D88F for ; Thu, 26 Nov 2015 03:57:02 +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 AC58D18CC7B9 for ; Thu, 26 Nov 2015 03:57:02 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 631281204E9; Thu, 26 Nov 2015 03:56:55 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id 153591204B9 for ; Thu, 26 Nov 2015 03:56:51 +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=gjgkrXTkOrEr6Em224UcUT25zsA=; b=nivpdnqDavZue3Q264 Nf2WQf3eWa2IHVOqgN5T0qNmNCGbmLxXZW2LpgknZCGuRRsyejnabqt/z6cXMlVI bAZsM2vUERUZLy+uR+3o2I2ShlJwLjJEqHhXj9iF6n3JzpWnM2bTTlYVCaCGXIpc RGXOuxT/4ZxQPQ1xCXQnBXadU= Received: by filter0560p1mdw1.sendgrid.net with SMTP id filter0560p1mdw1.28711.5656046C2A 2015-11-25 18:56:44.412135714 +0000 UTC Received: from herokuapp.com (ec2-23-20-227-238.compute-1.amazonaws.com [23.20.227.238]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id 7DJw3ldtSGG9RoKClEn2zA for ; Wed, 25 Nov 2015 18:56:44.240 +0000 (UTC) Date: Wed, 25 Nov 2015 18:56:44 +0000 From: 6ftdan@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: 46362 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11737 X-Redmine-Issue-Author: danielpclark X-Redmine-Sender: danielpclark 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS79QLZHx8qqCqa90sOU6+x6jsKYqmduB6TOMh 6NKTqokZTY5uZxmkpJP5K830tmpSJdjBkz5mVSZKcMUF2NhASdv/epfALJhiEr3AHXVC7ucTAuz0nS cDrE5tZE4pFygLdipWC0i/ya8ndT5uZdToNw X-ML-Name: ruby-core X-Mail-Count: 71686 Subject: [ruby-core:71686] [Ruby trunk - Feature #11737] 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 Daniel P. Clark. Since https://bugs.ruby-lang.org/issues/11734#note-3 has informed me the `_` is an IRB feature and Minitest uses `_()` in its test suite perhaps we should not use `_` for the case/when/then. How about `__case__` ~~~ruby case Enumerator.new do |y| y << 1; y << 2; y << 3; end when ->e{ 2.times{e.next}; true} then __case__.peek end == 3 ~~~ ---------------------------------------- Feature #11737: Pass in expression to then block in `case expression` https://bugs.ruby-lang.org/issues/11737#change-55090 * Author: Daniel P. Clark * Status: Open * 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/