# Instance variable as formal argument

**URL:** <https://www.ruby-forum.com/t/instance-variable-as-formal-argument/113381>\
**Category:** Development\
**Created:** [August 30, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/instance-variable-as-formal-argument/113381 "2007-08-30T15:12:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_ENDOH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@Yusuke\_ENDOH](https://www.ruby-forum.com/u/Yusuke_ENDOH)\
**Post date:** [August 30, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/instance-variable-as-formal-argument/113381/1 "2007-08-30T15:12:27Z")

</div>

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\<$G0l2s$@$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
