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 73FBB19E0032 for ; Mon, 7 Dec 2015 19:51:26 +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 7F93BB5D91D for ; Mon, 7 Dec 2015 20:23:03 +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 133A218CC7AF for ; Mon, 7 Dec 2015 20:23:04 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E8E12120461; Mon, 7 Dec 2015 20:23:02 +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 AFA9F120452 for ; Mon, 7 Dec 2015 20:22:58 +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=sfrjrp+GgwzU3xl01ArIkE/iBS4=; b=cz8IBJG4bP1Lmqdqau XsUeKqu0GvdaljDu42QolopEvOhfoNXr76draInaJDWRlQ8vEIGapDPiZHiN10aN 8vr4PT1p163JjCfixa5xZgIkscyPMHXofgwKXnsH+BVgzzvsqjqDzzYo6dkdcHaE MKH6pnrgmgsjKzA4jODqb+KXU= Received: by filter0824p1mdw1.sendgrid.net with SMTP id filter0824p1mdw1.31614.56656C0E36 2015-12-07 11:22:54.44362915 +0000 UTC Received: from herokuapp.com (ec2-54-234-135-239.compute-1.amazonaws.com [54.234.135.239]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id jKJNCUv7S3ulWWrikaQ1Ww for ; Mon, 07 Dec 2015 11:22:54.586 +0000 (UTC) Date: Mon, 07 Dec 2015 11:22:54 +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: 46600 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS4c7iJ7YrqgMZPmpTDx6Za2WPk61yCofyl3sB gDvQCfOqvlRjUk7EbMJJFZlq5fliGZJvh8NQt0w9MeFMN8lMYMYDE75xIC2yE0pZo6+tgSFMtZumSa Tvakdam+MWZ0EoDUPSOnBicr6o38Y8BPZDlA X-ML-Name: ruby-core X-Mail-Count: 71902 Subject: [ruby-core:71902] [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. Thank you. I appreciate your consideration. ---------------------------------------- Feature #11737: Pass in expression to then block in `case expression` https://bugs.ruby-lang.org/issues/11737#change-55305 * 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/