Case/when splat

[email protected]$G$9!#e(B

e$B!!<!$N%W%m%0%i%`$Oe(B :ok [email protected]$H;W$&$N$G$9$,!"e(Bruby
1.9.0
(2006-11-03) [x86_64-linux] e$B$G$Oe(B :ng2 e$B$H=PNO$5$l$^$9!#e(B

  ary = [1, 2]
  p case 1
  when :x, *ary
    :ok
  when :z
    :ng1
  else
    :ng2
  end

e$B!!<!$N%W%m%0%i%`$Oe(B :ok
e$B$HI=<($5$l$k$N$+$J!<$H;W$C$F$$$?$s$G$9$,!"e(B:ng e$B$He(B
e$BI=<($5$l$^$9!#$=$s$J$b$s$G$7$g$&$+!#e(B

  ary = []
  p case
  when false, *ary
    :ng
  else
    :ok
  end

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

In message “Re: [ruby-dev:29882] Re: case/when splat”
on Tue, 7 Nov 2006 00:12:33 +0900, Nobuyoshi N.
[email protected] writes:

|> e$B!!<!$N%W%m%0%i%`$Oe(B :ok e$B$HI=<($5$l$k$N$+$J!<$H;W$C$F$$$?$s$G$9$,!"e(B:ng e$B$He(B
|> e$BI=<($5$l$^$9!#$=$s$J$b$s$G$7$g$&$+!#e(B
|
|e$B$=$s$J$b$s$G$b$J$$$G$7$g$&!#e(B

e$B%P%0$G$7$g$&$M!#e(B

|when_check()e$B$N9=B$$,>/!9$$$^$$$A$C$]$$$G$9$,!#e(B

e$B$3$l$GD>$j$^$9$M!#<h$j9~$_$^$9!#e(B1.9CVSe$B%U%j!<%:$,6a$$$N$G!";de(B
e$B$NJ}$G:n6H$7$^$9!#e(B

[email protected]$G$9!#e(B

At Mon, 6 Nov 2006 14:35:02 +0900,
SASADA Koichi wrote in [ruby-dev:29860]:

e$B!!<!$N%W%m%0%i%`$Oe(B :ok [email protected]$H;W$&$N$G$9$,!"e(Bruby 1.9.0
(2006-11-03) [x86_64-linux] e$B$G$Oe(B :ng2 e$B$H=PNO$5$l$^$9!#e(B

[email protected]$H;W$$$^$9!#e(B

e$B!!<!$N%W%m%0%i%`$Oe(B :ok e$B$HI=<($5$l$k$N$+$J!<$H;W$C$F$$$?$s$G$9$,!"e(B:ng e$B$He(B
e$BI=<($5$l$^$9!#$=$s$J$b$s$G$7$g$&$+!#e(B

e$B$=$s$J$b$s$G$b$J$$$G$7$g$&!#e(B

when_check()e$B$N9=B$$,>/!9$$$^$$$A$C$]$$$G$9$,!#e(B

Index: eval.c

RCS file: /cvs/ruby/src/ruby/eval.c,v
retrieving revision 1.955
diff -p -U 2 -r1.955 eval.c
— eval.c 6 Nov 2006 10:27:58 -0000 1.955
+++ eval.c 6 Nov 2006 14:34:38 -0000
@@ -2701,8 +2701,8 @@ unknown_node(NODE *volatile node)
when_cond(VALUE v1, VALUE v2)
{

  • if (v1 == Qundef) {
  • return RTEST(v2);
  • if (v1 != Qundef) {
  • v2 = rb_funcall2(v2, eqq, 1, &v1);
    }
  • return RTEST(rb_funcall2(v2, eqq, 1, &v1));
  • return RTEST(v2);
    }

@@ -2724,5 +2724,7 @@ when_check(NODE *tag, VALUE val, VALUE s
break;
case NODE_SPLAT:

  • elm = splat_value(rb_eval(self, tag->nd_head));
  • tag = tag->nd_head;
  •  splat:
    
  • elm = splat_value(rb_eval(self, tag));
    for (i=0; i<RARRAY_LEN(elm); i++) {
    if (when_cond(val, RARRAY_PTR(elm)[i])) {
    @@ -2733,5 +2735,6 @@ when_check(NODE *tag, VALUE val, VALUE s
    case NODE_ARGSCAT:
    if (when_check(tag->nd_head, val, self)) return Qtrue;
  • return when_check(tag->nd_body, val, self);
  • tag = tag->nd_body;
  • goto splat;
    case NODE_ARGSPUSH:
    if (when_check(tag->nd_head, val, self)) return Qtrue;

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs