On 29/07/05, "Peñá, Botp" <botp / delmonte-phil.com> wrote:
> Hi All,
> 
> I may not be feeling well today, so pardon me pls.
> 
> I am modifying/cleaning many scripts here (most of them just a page long,
> two at most, and most of them coming fr perl/bash origin).
> 
> I encountered a wall though.
> 
> Consider,
> 
> >cat test.rb
> 
> #sample script---------------->8
> foo=["a","b","c"]
> 
> def mfoo
>     foo.each do |f|
>         p f
>     end
> end
> 
> # go-go-go!
> mfoo
> #end sample script------------>8
> 
> i just enclosed the some commands with def mfoo / end to make a new method
> mfoo and make my script cleaner, and besides, i may be calling mfoo again.
> 
> running the above, i get:
> 
> >test.rb
> 
> >test.rb:4:in `mfoo': undefined local variable or method `foo'
>         from test.rb:9
> 
> 
> So how can i force foo visible to mfoo()?
> 
> Thanks in advance.
> -botp

If you really want this, you could prepend an @ to the foo

$ cat mfoo.rb 
@foo = [1,2,3]
foo = [5,6,7]

def afoo
  @foo
end

def mfoo
  foo
end

p afoo
p mfoo
$ ruby mfoo.rb 
[1, 2, 3]
mfoo.rb:9:in `mfoo': undefined local variable or method `foo' for
#<Object:0xb7ef79c0 @foo=[1, 2, 3]> (NameError)
        from mfoo.rb:13

regards,

Brian

-- 
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/