------art_32413_12815417.1182995168413
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 6/28/07, Frank Church <vfcforums / gmail.com> wrote:
>
>
> I have this sequence of commands to write a list of values to a file
>
> f  ile.new(configfile, File::CREAT|File::WRONLY, 0700)
> header_commands.each {|x| f.puts x }
> mysql_commands.each {|x| f.puts x }
> dir_commands.each {|x| f.puts x }
> scp_commands.each {|x| f.puts x }
>
> Is there a way to do something like
>
> [header_commands, mysql_commands, dir_commands, scp_commands] each {|x|
> f.puts x }
>
> I know there must be a number of ruby ways to do it.
>
> Any examples?
>
>
> - Frank


Just a stab.  Besides a normal nested loop, you could add all the array's of
commands together and them join them

puts ( header_commands + mysql_commands + dir_commands + scp_commands
).join("\n")

or a little less hard coded

puts ( commands.inject( [] ){ |list, current| list + current }.join("\n")

Cheers
Daniel

------art_32413_12815417.1182995168413--