From: Brandon Larocque Date: 2009-08-25T04:24:08+09:00 Subject: Ruby eval I am trying to learn Ruby as a first language, ( I tended to go back and forth over languages in my studies, but I plan, now, to focus on Ruby ), and came across a confusing problem. My brother likes to play Mafia Wars on facebook and asked me to come up with something simple. So I put a little something together, and it involved the eval function. From what I've read, recently, people tend to look down on the eval function? Why is this? I have a few classes that have multiple names, so I decided to use it to work through the problem I was having ( I didn't want to write a bunch of loops ). For example : ( $jobarea == "hi" or $jobarea == "es" ) ? (loop = 9) : ( ($jobarea == "ca") ? (loop = 8) : (loop = 7) ) expcost = [] ; exppay = [] ; pay = [] ; name = [] for i in (1..loop) do eval("expcost.push $#{$jobarea}_job#{i}.expcost") eval("exppay.push $#{$jobarea}_job#{i}.exppay") eval("pay.push $#{$jobarea}_job#{i}.pay") eval("name.push $#{$jobarea}_job#{i}.name") end Is there any way that I might be able to do this without eval? Or is it alright the way I have done it? Regards, Brandon LaRocque -- Posted via http://www.ruby-forum.com/.