From: wannes Date: 2005-07-29T19:22:05+09:00 Subject: Re: [newbie] make local var visible On 29/07/05, "Pe�a, Botp" wrote: > #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 > >test.rb:4:in `mfoo': undefined local variable or method `foo' > from test.rb:9 > So how can i force foo visible to mfoo()? def mfoo ... end creates a new scope (or how would you say that in proper naming), and thus forgets about local variables defined elsewhere, you can't access foo from within the method. I think you have 2 options here (maybe more, but these are the ones I can come up with as a newbie myself): 1) pass foo as an argument. def mfoo(foo) ... end mfoo(foo) 2) make foo an instance-variable @foo = [..] def mfoo @foo.each... end grtz, wannes