From: Aatch Random Date: 2007-06-15T13:07:31+09:00 Subject: Re: Reasonable practice? Trans wrote: > It the following reasonable? How thread safe is it? > > class X > attr :type > > def initialize(ary) > @ary = ary > end > > def go > @ary.each { |x| > @type = x > run > } > end > > def run > puts type > end > > end > > X.new(['a', 'b', 'c']).go > > Is changing the instance variable through each iteration a bad idea? > Of course I could pass the type to #run as an argument, but I'm > experimenting with the concept of "service points" and was wondering > if type could safely be one in this case. My alternative to keep type > as a serve point is to create a Runner class that took type as its > initialize argument, but that seems code heavy. > > Thanks, > T. If you just want to print out all of the members of an array, it looks fine to me. Although maybe you could just substitute the 'run' for 'puts x'. It means about 4 less lines and one or two less variables. Unless you plan to use that 'type' variable another time. But thats just me, i dont always like creating one-use methods, especially such small ones. -- Posted via http://www.ruby-forum.com/.