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 063B519C02F7 for ; Wed, 25 Nov 2015 05:28:32 +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 B9F30B5D82F for ; Wed, 25 Nov 2015 05:59:35 +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 BFC0E18CC7E9 for ; Wed, 25 Nov 2015 05:59:35 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 83BEA12048B; Wed, 25 Nov 2015 05:59:34 +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 B6F23120420 for ; Wed, 25 Nov 2015 05:59:30 +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=ANhDJMm6xI+CK4OBc9A31C8NQfc=; b=BPxFeL95U97dgsQumm A+rrktnL00QxxxOE7cGnO4qzpSCSUXxZvYGlNZTzwskxHz0tbqdb+lOFWQANbcB7 gk5lxbPui5SE6HqXEisCNlSjBgd4aaZAyQ7+bH534rqmrvcTmv5u1aC9PWpbdgW0 PUsvgBnfFCNd1O+/z99uJZIoo= Received: by filter0860p1mdw1.sendgrid.net with SMTP id filter0860p1mdw1.4175.5654CFAB32 2015-11-24 20:59:23.63832396 +0000 UTC Received: from herokuapp.com (ec2-54-145-198-130.compute-1.amazonaws.com [54.145.198.130]) by ismtpd0002p1iad1.sendgrid.net (SG) with ESMTP id xqXFgFFtQI6Y2cY7GdV34A for ; Tue, 24 Nov 2015 20:59:23.438 +0000 (UTC) Date: Tue, 24 Nov 2015 20:59:23 +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: 46339 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7oIsx/60vwxm4au5AMYgMbftcwIQDyyR9C/7 yNNdCrKACWnPav0OMosqJ1cnp8RagPUolypSzKPoEy9t8b6SYUaHWzOo7jG8HuPRL0EH/qwltg6Wy7 hAjFxq73dIheoF+IPD5Vdh2154fUqQ441n2i X-ML-Name: ruby-core X-Mail-Count: 71664 Subject: [ruby-core:71664] [Ruby trunk - Feature #11737] [Open] 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 reported by Daniel P. Clark. ---------------------------------------- Feature #11737: Pass in expression to then block in `case expression` https://bugs.ruby-lang.org/issues/11737 * 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/