From: Brian Candler Date: 2011-02-05T05:54:39+09:00 Subject: Re: Arrays and defs botp wrote in post #979636: > since you're doing it procedurally, then why not pass list as a param. Good idea here. > scheme 2, you can make list a class variable, > > eg, > > def do_stuff > @@list.each_index do |i| > puts @@list[i] > end > end > #=> nil I'd recommend avoiding class variables (@@) as something of a ruby misfeature - especially outside of an explicit class. Even a global variable ($list) would be better here. However, in a typical application, the data and the methods would be part of the same object. class Thing def initialize(list) @list = list end def do_stuff @list.each do |elem| puts elem end end end thing = Thing.new(["a","b","c"]) thing.do_stuff -- Posted via http://www.ruby-forum.com/.