From: kallen Date: 2009-08-25T08:00:05+09:00 Subject: Re: Ruby eval It's not so much that eval is looked down on, it's very useful under the right circumstances, it's just that it's like putting in a nail with a sledgehammer, there's no need for it. From what I can tell from your code you have a bunch of variables named like es_job1, es_job2, etc. Rather then encode information like jobarea and the number in the variable name, use a data structure to do it. For instance you could use a hash of arrays like so: jobs = { "hi" => [Job.new, Job.new, Job.new], "es" => [Job.new, Job.new, Job.new] } Then most of your code becomes moot. You don't need the loop variable because you can loop across the hash and the arrays with each or other methods like it. For example to get an array of all the expcosts like you are doing could be done like so: expcost = jobs.values.collect{|v| v.collect{|job| job.expcost}}.flatten Or even better, you can avoid all this by keeping all jobs in one array and just using collect on the array. :) Basically what you should take away from this is 1) that eval is rarely the right choice and 2) that there are data structures like arrays and hashes in ruby for precisely these kinds of things, use them! Also, for the first line you should be using if or case instead of the ternary operator (?).