From: "Jesús Gabriel y Galán" Date: 2007-09-04T22:56:22+09:00 Subject: Re: Feeding a codeblock/function with an array or something similar? On 9/4/07, kazaam wrote: > I have a codeblock like this: > > def foobar(command,customerrormessage) > if not system(command) > puts customerrormessage > exit > end > end > > > and then many calls of it like: > > foobar('rm something','Error I could'nt remove something') > foobar('apt-get install thishere','Error while installing the packet') > foobar('module-assistant a-i mymodule','Error while installing the module') > In pascal I would simply create a multi-dimensional array[x,y] and fill it with the > commands and the corresponding error-messages but how to do this in ruby? > There are no arrays like the mentioned on or? Or do you have a even better > solution for this? I assume the order in which you execute the commands is important, so I would do it like this (not tested): command_list = [] command_list << {:command => 'rm something', :error_msg => 'I couldn't remove something'} command_list << {:command => 'apt-get install thishere', :error_msg => 'Error while installing the packet'} command_list << {:command => 'module-assistant a-i mymodule', :error_msg => 'Error while installing the module'} process_commands(command_list) the process_commands can be something like: def process_commands(command_list) command_list.each do |command| if not system(command[:command]) puts command[:error_msg] end end end Don't know if you want to break the execution of the other commands if something fails, in which case you can return from the method inside the if, but this can get you started as an idea. Jesus.