[#71931] [Ruby trunk - Feature #11786] [Open] [PATCH] micro-optimize case dispatch even harder — normalperson@...

Issue #11786 has been reported by Eric Wong.

9 messages 2015/12/08

[ruby-core:72247] [Ruby trunk - Feature #11737] Pass in expression to then block in `case expression`

From: Joseph Jones <joeyi5216@...>
Date: 2015-12-18 04:05:54 UTC
List: ruby-core #72247
Joseph Jones liked your message with Boxer. On December 2, 2015 at 21:07:=
58 MST, s.wanabe=40gmail.com wrote:Issue =2311737 has been updated by =5F=
 wanabe.Nobuyoshi Nakada wrote:> It reminded me a rejected proposal:> > =7E=
=7E=7Eruby> case expr> when matcher =3D> result> ...> end> =7E=7E=7EIs th=
e proposal =5Bruby-dev:17615=5D=3FOr other=3F----------------------------=
------------=46eature =2311737: Pass in expression to then block in =60ca=
se expression=60https://bugs.ruby-lang.org/issues/11737=23change-55214* A=
uthor: Daniel P. Clark* Status: Open* Priority: Normal* Assignee: -------=
---------------------------------Ruby's =60case =60 scenario allows the e=
xpression to be tested in the =60when=60 test with =60:=3D=3D=3D=60, but =
in the then block the expression is not accessible. Only if the expressio=
n has been assigned to a variable beforehand can it be checked.=7E=7E=7Er=
ubycase 4when ->i=7B puts :when; true=7D ->i=7B puts i=7Delse :fooend=23 =
when=23 =3D> =23 case 4when ->i=7B puts :when; true=7D puts =5Felse :fooe=
nd=23 when=23 =23=23 =3D> nil case 4when 4then =5Fend=23 =3D> nilcase 4wh=
en 4then ->i=7Bputs i=7Dend=23 =3D> =23 =7E=7E=7EIf some one wanted to gi=
ve 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 =60=5F=60 variable during a case/when/then scenario. Here's a rath=
er contrived example use case.=7E=7E=7Erubycase Enumerator.new do =7Cy=7C=
 y when ->e=7B 2.times e.next; true=7Dthen =5F.peekend =3D=3D 3=7E=7E=7E-=
- https://bugs.ruby-lang.org/     

In This Thread

Prev Next