Instance variable as formal argument

e$B1sF#$H?=$7$^$9!#e(B

e$B2>0z?t$K%$%s%9%?%s%9JQ?t$r=q$$$?$i!"%$%s%?%W%j%?$KFs2s$bGO</$K$5$l$ke(B
e$B$s$G$9$,;EMM$G$7$g$&$+!#e(B

$ ./ruby -ve ‘def initialize(@foo); end;’
ruby 1.9.0 (2007-08-30 patchlevel 0) [i686-linux]
-e:1: formal argument cannot be an instance variable
def initialize(@foo); end;
^
-e:1: formal argument must be local variable
def initialize(@foo); end;
^

e$B0J2<[email protected]$1$K$J$j$^$7$?!#e(B

Index: parse.y

— parse.y (revision 13320)
+++ parse.y (working copy)
@@ -4170,10 +4170,12 @@
f_arg_item : f_norm_arg
{
/%%%/

  •                   if (!is_local_id($1))
    
  •                       yyerror("formal argument must be local 
    

variable");

  •                   arg_var($1);
    
  •                   $$ = NEW_ARGS_AUX($1, 1);
    
  •                   if ($1) {
    
  •                       if (!is_local_id($1))
    
  •                           yyerror("formal argument must be local
    

variable");

  •                       arg_var($1);
    
  •                       $$ = NEW_ARGS_AUX($1, 1);
    
  •                   }
                  /*%
                  %*/
                  }
    

e$B$=$b$=$b2>0z?t$K%$%s%9%?%s%9JQ?t$r=q$1$J$$$N$O$J$<$G$7$g$&$+!#e(B
e$B%m!<%+%kJQ?t$G<u$1$F%$%s%9%?%s%9JQ?t$KBeF~$9$k$N$O!“JQ?tL>$re(B 3
e$B2s$be(B
e$B=q$+$J$$$H$$$1$J$$$N$G!”$H$F$b>iD9$G$9!#e(B

def initialize(foo)
@foo = foo
end

e$B;d$N>l9g!"<+J,$G%/%i%9$rDj5A$7$?$/$J$$M}M3$N0l$D$K$J$C$F$$$^$9!#e(B

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