From: "Jesús Gabriel y Galán" Date: 2007-09-04T23:21:53+09:00 Subject: Re: Feeding a codeblock/function with an array or something similar? On 9/4/07, kazaam wrote: > Hi thanks, > I would do this method to make my code smaller and better looking but the > whole: > > > 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'} > > would blow the code even more than my momentan solution :) It's easy to read this from a YAML configuration file or from a DB, so the actual list of commands is not hardcoded. It all depends on the complexity of your application. Of course you can also use other structures like a multidimensional array, or a unidimensional array with [cmd1, msg1, cmd2, msg2...], but I like the hash cause it makes clear what each element is. I'd rather not have arrays where you need to know that the first element is something and the second is something else, but for simple cases it might be enough. YMMV, though. Jesus.