From: Xiong Chiamiov Date: 2008-09-12T07:07:35+09:00 Subject: Re: pass by reference in each loop Robert Klemme wrote: > On 11.09.2008 23:12, Xiong Chiamiov wrote: > >> Robert's solution would allow me to only write the function name once, >> but the variables I'd still have to type twice, and I really like DRY. >> >> My first thought was to store a list of all those variables in an array >> and loop through them, as it's then very easy to add an additional >> variable. Perhaps I'm approaching this the complete wrong way, though? > > That's quite near to what I suggested: just drop all the @a, @b etc. and > stuff everything in an array - or have multiple arrays, one per class of > data (i.e. data which undergoes wml and data which does not). Anyway, > chances are that you'll be able to find an elegant solution without > needing to change the language. > > Kind regards > > robert I don't think I understood what you were suggesting the first time. If I understand what you're suggesting, it is to have the values themselves in the array, rather than variables pointing *to* those values, yes? I need to know specifically which values are which, however, as they get passed back into different parts of the output, so I'm thinking I'd have to use a hash, something like hash = { 'a' => 'this is actually input', 'b' => 'not hardcoded', ... } so that I could assign them appropriately afterwards: hash.each {|key, value| key = value} although, looking at that now, I don't think that it would work. But as far as hash mapping (if that's what I have to do), I suppose I could use one of the methods in this thread (http://www.nabble.com/Iterating-through-a-hash-td19074540.html), right? I appreciate your help. -- Posted via http://www.ruby-forum.com/.