From: Brian Candler Date: 2011-02-24T18:09:13+09:00 Subject: Re: a, b = Array.new(2).map!{|x| data.dup} Stefan Salewski wrote in post #983443: > The code is related to handling configuration files, I have a basic > configuration set, a hash called @output. And variants for on screen, > pdf, png export. In that case, I'd say you'd be better off avoiding all the separate instance variables for each variant, and make it data-driven. Then you can interate over the variants, which will naturally avoid the repeated code. FORMATS = [:scr, :png, :pdf, :svg, :ps] ... @configs = {} FORMATS.each { |k| @configs[k] = @output.dup } Now you have @configs[:scr], @configs[:png] etc, all pointing to separate copies of @output. And if you want to add another format in future, it's a trivial change. (Aside: please do not post variants of this code using 'inject', because it's stupid here. You know who you are. Thank you.) Regards, Brian. -- Posted via http://www.ruby-forum.com/.