From: botp Date: 2011-02-05T01:30:07+09:00 Subject: Re: Arrays and defs On Fri, Feb 4, 2011 at 8:04 PM, Jens Finnäs wrote: > Is it not possible to call an array outside a defintion? Like this: > list = Array.new ^^^^^ lose this. not needed since you created list below > list = ["a", "b", "c"] > > def do_stuff() >  list.each_index do |i| >    puts list[i] >  end > end > do_stuff() list would not be visible since we're in oo env and encapsulation is enforced. > If I define list inside do_stuff() the script works. My plan was to > build an array through several functions. since you're doing it procedurally, then why not pass list as a param. eg, def do_stuff(list) list.each_index do |i| puts list[i] end end #=> nil list = ["a", "b", "c"] #=> ["a", "b", "c"] do_stuff(list) a b c #=> ["a", "b", "c"] scheme 2, you can make list a class variable, eg, def do_stuff @@list.each_index do |i| puts @@list[i] end end #=> nil @@list = ["a", "b", "c"] #=> ["a", "b", "c"] do_stuff a b c #=> ["a", "b", "c"] best regards -botp