# Variable after when

**URL:** <https://www.ruby-forum.com/t/variable-after-when/68487>\
**Category:** Development\
**Created:** [September 13, 2006, 2:24am UTC](https://www.ruby-forum.com/t/variable-after-when/68487 "2006-09-13T02:24:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nobu](https://www.ruby-forum.com/u/nobu)\
**Post date:** [September 13, 2006, 2:24am UTC](https://www.ruby-forum.com/t/variable-after-when/68487/1 "2006-09-13T02:24:18Z")

</div>

e$B$J$+$@$G$9!#e(B

e$B0JA0$A$g$C$HDs0F$7$?3P$($,$"$j$^$9$,!"e(Brescuee$BF1MMe(Bwhene$B$NHf3S7k2Le(B  
e$B$rJQ?t$KBeF~$9$k9=J8$O$I$&$G$7$g$&$+!#e(BRegexp#===e$B$NLa$jCM$be(B  
MatchDatae$B$K$9$k$3$H$G!"e(B$~e$B$r;H$&I,MW$r8:$i$;$k$H;W$$$^$9!#e(B

# Index: eval.c

RCS file: /cvs/ruby/src/ruby/eval.c,v  
retrieving revision 1.945  
diff -p -u -2 -r1.945 eval.c  
— eval.c 10 Sep 2006 00:18:18 -0000 1.945  
+++ eval.c 12 Sep 2006 23:53:08 -0000  
@@ -2686,14 +2686,15 @@ unknown\_node(NODE \*volatile node)

static int  
-when\_cond(VALUE v1, VALUE v2)  
+when\_cond(VALUE v1, VALUE v2, volatile VALUE \*result)  
{

- if (v1 == Qundef) {
- return RTEST(v2);

- if (v1 != Qundef) {
- v2 = rb\_funcall2(v2, eqq, 1, &v1);  
}

- return RTEST(rb\_funcall2(v2, eqq, 1, &v1));

- \*result = v2;
- return RTEST(v2);  
}

static int  
-when\_check(NODE \*tag, VALUE val, VALUE self)  
+when\_check(NODE \*tag, VALUE val, VALUE self, volatile VALUE \*result)  
{  
VALUE elm;  
@@ -2704,5 +2705,5 @@ when\_check(NODE \*tag, VALUE val, VALUE s  
while (tag) {  
elm = rb\_eval(self, tag-\>nd\_head);

- 

```
  if (when_cond(val, elm)) {

```

- 

```
  if (when_cond(val, elm, result)) {
  return Qtrue;
  }

```

@@ -2713,5 +2714,5 @@ when\_check(NODE \*tag, VALUE val, VALUE s  
elm = svalue\_to\_avalue(rb\_eval(self, tag-\>nd\_head));  
for (i=0; i\<RARRAY\_LEN(elm); i++) {

- 

```
  if (when_cond(val, RARRAY_PTR(elm)[i])) {

```

- 

```
  if (when_cond(val, RARRAY_PTR(elm)[i], result)) {
  return Qtrue;
  }

```

@@ -2719,11 +2720,11 @@ when\_check(NODE \*tag, VALUE val, VALUE s  
break;  
case NODE\_ARGSCAT:

- if (when\_check(tag-\>nd\_head, val, self)) return Qtrue;
- return when\_check(tag-\>nd\_body, val, self);

- if (when\_check(tag-\>nd\_head, val, self, result)) return Qtrue;
- return when\_check(tag-\>nd\_body, val, self, result);  
case NODE\_ARGSPUSH:

- if (when\_check(tag-\>nd\_head, val, self)) return Qtrue;
- if (when\_cond(val, rb\_eval(self, tag-\>nd\_body))) return Qtrue;

- if (when\_check(tag-\>nd\_head, val, self, result)) return Qtrue;
- if (when\_cond(val, rb\_eval(self, tag-\>nd\_body), result)) return Qtrue;  
default:

- if (when\_cond(val, rb\_eval(self, tag))) return Qtrue;

- if (when\_cond(val, rb\_eval(self, tag), result)) return Qtrue;  
break;  
}  
@@ -2874,5 +2875,8 @@ rb\_eval(VALUE self, NODE \*n)  
ruby\_frame-\>this\_func,  
ruby\_frame-\>this\_class);

- 

```
  if (when_check(node->nd_head, val, self)) {

```

- 

```
  if (when_check(node->nd_head->nd_cond, val, self, &result)) {

```

- 

```
      if (node->nd_head->nd_body) {

```

- 

```
  	assign(self, node->nd_head->nd_body, result, Qfalse);

```

- 

```
      }
      node = node->nd_body;
      goto again;

```

# Index: parse.y

RCS file: /cvs/ruby/src/ruby/parse.y,v  
retrieving revision 1.458  
diff -p -u -2 -r1.458 parse.y  
— parse.y 6 Sep 2006 04:25:53 -0000 1.458  
+++ parse.y 12 Sep 2006 23:44:31 -0000  
@@ -3392,12 +3392,12 @@ brace\_block : ‘{’  
;

-case\_body : keyword\_when args then  
+case\_body : keyword\_when args exc\_var then  
compstmt  
cases  
{  
/_%%%_/

- 

```
  	$$ = NEW_WHEN($2, $4, $5);

```

- 

```
  	$$ = NEW_WHEN(NEW_IF($2, $3, 0), $5, $6);
      /*%

```

- 

```
  	$$ = dispatch3(when, $2, $4, escape_Qundef($5));

```

- 

```
  	$$ = dispatch4(when, $2, $3, $5, escape_Qundef($6));
      %*/
      }

```

# Index: re.c

RCS file: /cvs/ruby/src/ruby/re.c,v  
retrieving revision 1.154  
diff -p -U 2 -r1.154 re.c  
— re.c 31 Aug 2006 10:47:43 -0000 1.154  
+++ re.c 12 Sep 2006 23:57:05 -0000  
@@ -1658,7 +1658,7 @@ rb\_reg\_eqq(VALUE re, VALUE str)  
start = rb\_reg\_search(re, str, 0, 0);  
if (start \< 0) {

- return Qfalse;

- return Qnil;  
}

- return Qtrue;

- return rb\_backref\_get();  
}

---

<div class="post-metadata">

**Author:** ![nobu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@nobu](https://www.ruby-forum.com/u/nobu)\
**Post date:** [September 13, 2006, 4:28am UTC](https://www.ruby-forum.com/t/variable-after-when/68487/2 "2006-09-13T04:28:33Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:29567] variable after when”  
on Wed, 13 Sep 2006 09:23:03 +0900, Nobuyoshi N.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|e$B0JA0$A$g$C$HDs0F$7$?3P$($,$"$j$^$9$,!"e(Brescuee$BF1MMe(Bwhene$B$NHf3S7k2Le(B  
|e$B$rJQ?t$KBeF~$9$k9=J8$O$I$&$G$7$g$&$+!#e(BRegexp#===e$B$NLa$jCM$be(B  
|MatchDatae$B$K$9$k$3$H$G!"e(B$~e$B$r;H$&I,MW$r8:$i$;$k$H;W$$$^$9!#e(B

e$B0-$$$1$IDq93$,$“$j$^$9!#e(Bcasee$BJ8$Ne(Ba ===  
be$B$NCM$OC1$J$k??56CM$Ne(B  
e$B$O$:$J$N$G$=$NCM$r\<h$j=P$9$N$K0UL#$,$”$k%1!\<%9$,$+$J$jFC\<l$Je(B  
e$B$N$H!“e(Brescuee$B$H$NN`?d$G$$$1$PBeF~$5$l$k$N$Oe(Bcasee$B$N8e$m$NCMe(B(e$BHfe(B  
e$B3SBP\>]e(B)e$B$G$”$C$Fe(B===e$B$N7k2L$G$O$J$$$3$H$H$+!#e(B

e$B8zG=$OM}2r$G$-$k$s$G$9$1$I$M$(!#e(B
