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 4F9B619C05A5 for ; Thu, 3 Dec 2015 12:36:43 +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 4618BB5D839 for ; Thu, 3 Dec 2015 13:08:09 +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 94A2C18CC7B9 for ; Thu, 3 Dec 2015 13:08:09 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 79B7F1204A9; Thu, 3 Dec 2015 13:08:08 +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 7AB04120479 for ; Thu, 3 Dec 2015 13:08:04 +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=BfDw2sDOQqiSJzAsfxxuSzE1eC8=; b=C7mHaGOFYBqIvYXm7c 2a09OwtO8yE8qjmEb9cstHStrOox2EmhofdS32m+8IoL+uZ+YhTX+FoYgx8yeqFd Jw+c+EpimkI2wg1OYY+Fr9NA9/Pw9AQqP+RrQH0zpG77g8H6SU5iSF6cN4g5Muyr N6dWhOk8kAicWQqIi7KBWLm9o= Received: by filter0086p1mdw1.sendgrid.net with SMTP id filter0086p1mdw1.25527.565FC01F1 2015-12-03 04:07:59.005508892 +0000 UTC Received: from herokuapp.com (ec2-54-157-216-22.compute-1.amazonaws.com [54.157.216.22]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id qt-zYIQQRluy2Ov5ANv7TQ for ; Thu, 03 Dec 2015 04:07:58.811 +0000 (UTC) Date: Thu, 03 Dec 2015 04:07:58 +0000 From: s.wanabe@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: 46497 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11737 X-Redmine-Issue-Author: danielpclark X-Redmine-Sender: wanabe 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS6VQ1EKKbbEFTK9I7rlqichbHzsxlolwveq8Q LTsCP5gdWRVp56N50hB+lDmCQa7a4V5Cwb1i29FMJP485pJYZyYnQFZyoz79L4s0RHwSjJJAe4MIZT FW87nReYfDpnBryMmD+b/OpZaGWHumg7bZ4t X-ML-Name: ruby-core X-Mail-Count: 71810 Subject: [ruby-core:71810] [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 _ wanabe. Nobuyoshi Nakada wrote: > It reminded me a rejected proposal: > > ~~~ruby > case expr > when matcher => result > ... > end > ~~~ Is the proposal [ruby-dev:17615]? Or other? ---------------------------------------- Feature #11737: Pass in expression to then block in `case expression` https://bugs.ruby-lang.org/issues/11737#change-55214 * 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/